Tim Chase
unread,Oct 3, 2013, 8:45:39 AM10/3/13Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to django...@googlegroups.com
I've been trying to reduce some code in a new project, and I have a
number of objects where I have the main class, and an archival
version of the same class, something like
def Thing(Model):
last_updated = DateTimeField(...)
who_updated = ForeignKey(User)
field1 = ...
field2 = ...
...
def ThingArchive(Model):
# pseudo-type declaration
original_id = Thing.id.__class__ # whether Int or Guid
last_updated = DateTimeField(...)
who_updated = ForeignKey(User)
field1 = ...
field2 = ...
...
such that every time Thing is updated+saved, the previous copy's
information gets archived in ThingArchive, storing the original
Thing.id as original_id (the id might be an integer or a GUID
depending on the table).
For one class, this isn't a particularly big deal, but I've got a
number of these class-pairs and the code duplication is starting to
get out of hand. Is there a pattern I should be using to abstract
this archiving logic?
Thanks,
-tkc