Jeez what an easy solution, but I sure with InlineModelAdmin would
just do it for us and save us the code.
In models.py (genericized and not tested, sorry for any syntax
errors):
class MyJoinTable(model.Model):
parent_table = models.ForeignKey(ParentTable)
...
def save(self,*args,**kwargs):
if not self.created:
self.created = datetime.datetime.now()
if not self.parent_table.updated_by:
self.created_by = self.parent_table.created_by
else:
self.created_by = self.parent_table.updated_by
else:
self.updated = datetime.datetime.now()
if self.parent_table.updated:
self.updated_by = self.parent_table.updated_by
else:
self.updated_by = self.parent_table.created_by
super(MyJoinTable,self).save(*args,**kwargs)
Note that this depends on having the same audit fields (created,
created_by, updated, updated_by) in the parent and join tables, and
only making the join tables addable/editable from within
InlineModelAdmin. But that was the whole point, afterall. This is
basic database parent/child auditing functionality, and should be in
Django core IMHO. Maybe it is and I'm just still half-blind.
Hope this saves someone else 10 hours of hacking.
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.