Storing Wiki Revisions On Google App Engine/django - Modifying This Existing Code
Solution 1:
The code in your first snippet is not a model - it's a custom class that uses the low-level datastore module. If you want to extend it, I would recommend throwing it out and replacing it with actual models, along similar lines to the Article model you demonstrated in your second snippet.
Also, they're App Engine models, not Django models - Django models don't work on App Engine.
Solution 2:
I created this model (which mimics the Page class):
class Revision (db.Model):
name = db.StringProperty(required=True)
created = db.DateTimeProperty(required=True)
modified = db.DateTimeProperty(auto_now_add=True)
content = db.TextProperty(required=True)
user = db.UserProperty()
In the Save() method of the Page class, I added this code to save a Revision, before I updated the fields with the new data:
r = Revision(name = self.name,
content = self.content,
created = self.created,
modified = self.modified,
user = self.user)
r.put()
I have the wiki set up now to accept a GET parameter to specify which revision you want to see or edit. When the user wants a revision, I fetch the Page from the database, and replace the Page's Content with the Revision's Content:
page = models.Page.load(title)
if request.GET.get('rev'):
query = db.Query(models.Revision)
query.filter('name =', title).order('created')
rev = request.GET.get('rev')
rev_page = query.fetch(1, int(rev))
page.content = rev_page.content
Post a Comment for "Storing Wiki Revisions On Google App Engine/django - Modifying This Existing Code"