In the past, I created the Django wiki, and it was pretty simple to make a page table for the current entries in the wiki, and then save the old versions in the Revision table.
Most recently, I decided to create a website in the Google App Engine, and I used the wiki code that another programmer wrote. Since he created his page model in a complicated way (at least with my help) using Entities, I'm not sure how to create a Revision table and integrate it with his page model.
Here is the relevant code. Can someone help me write a Revision model and integrate saving changes using the Save method of the page model?
class Page(object):
def __init__(self, name, entity=None):
self.name = name
self.entity = entity
if entity:
self.content = entity['content']
if entity.has_key('user'):
self.user = entity['user']
else:
self.user = None
self.created = entity['created']
self.modified = entity['modified']
else:
now = datetime.datetime.now()
self.content = '<h1>' + cgi.escape(name) + '</h1>'
self.user = None
self.created = now
self.modified = now
def save(self):
"""Creates or edits this page in the datastore."""
now = datetime.datetime.now()
if self.entity:
entity = self.entity
else:
entity = datastore.Entity('Page')
entity['name'] = self.name
entity['created'] = now
entity['content'] = datastore_types.Text(self.content)
entity['modified'] = now
if users.GetCurrentUser():
entity['user'] = users.GetCurrentUser()
elif entity.has_key('user'):
del entity['user']
datastore.Put(entity)
, : http://code.google.com/p/google-app-engine-samples/downloads/list
GAE Django, , , . , . :
class Article(db.Model):
author = db.UserProperty()
title = db.StringProperty(required=True)
text = db.TextProperty(required=True)
tags = db.StringProperty(required=True)
date_created = db.DateProperty(auto_now_add=True)