I want to create a \"What\'s New\" section that lists all of the database changes in the last day. I\'ve added an \"updated\" field to my models:
class Film
I don't know of any way to run a select across multiple tables… So, unless you want to use my suggestion below, you'll just have to loop across all 'updatable' models.
However, you might want to consider having an UpdatedItems
model, which might be something like:
class ItemUpdate(m.Model):
when = m.DateTimeField(...)
instance = m.GenericForeignKey(...)
field = m.CharField(...)
old_value = m.CharField(...)
new_value = m.CharField(...)
Then use the post_save
signal to populate it:
form django.db.models.signals import post_save
def handle_post_save(sender, instance, *args, **kwargs):
ItemUpdate(instance=instance, ...).save()
I don't know off the top of my head how to figure out which fields are updated… But I'm sure someone's asked about it on Google.