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



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20131003074539.7c9da54b%40bigbox.christie.dr.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to