I do like this a lot. If I use post_save, is there a way to grab the field that is altered? I know the admin page seems to be able to determine the changed field. . .
On Oct 26, 9:41 am, bruno desthuilliers <bruno.desthuilli...@gmail.com> wrote: > On 26 oct, 13:25, Ed <edmund.rog...@gmail.com> wrote: > > > > > > > > > > > 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(models.Model): > > . > > . > > . > > updated = models.DateTimeField(auto_now=True) > > > class Actor(models.Model): > > . > > . > > . > > updated = models.DateTimeField(auto_now=True) > > > Now I want to query across all of my models to get a date-sorted list > > of the most recent changes. How do I query the "updated" field across > > multiple models? Is this the most efficient way to achieve the primary > > purpose? > > > What if I wanted to be more specific and list the actual field that > > was altered within each model? > > Another solution is to have a specific "LastChange" model with a > GenericForeignKey on your other models (the ones you want to monitor) > and hook into the appropriate signal (models.signals.pre_save or > models.signals.post_save look like a good start) to feed it with > relevant data. > > The neat points are that: > > 1/ you can monitor just any model, without having to add special > fields > 2/ you only have one table to query to build your "what's new" section > (depending on what infos you store in LastChange, you may not need to > get at the changed object at all) > > HTH -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.