Use one model with a field to indicate whether or not this is the archival (backup?) version. This could be your original_id field, which might be better represented as a null-able foreign key field on self. Update step:
delete any instances whose "original" is this field (the reverse reference manager works for this) save a copy of the current instance (with any changes you want, and a null "original" field) update the "original" field of the old copy to point to the new one. This can be extended to more than one level of backup. On Thu, Oct 3, 2013 at 8:45 AM, Tim Chase <django.us...@tim.thechases.com>wrote: > 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 django-users+unsubscr...@googlegroups.com. > To post to this group, send email to django-users@googlegroups.com. > 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. > -- 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 django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. 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/CAB%2BAj0uvRYAgH2L8Yf3SeZFfWT5akB5a70255auB%2BkdLr5xShw%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.