Maybe -- in fact, almost certainly not -- the best way, but this is
how I do that kind of thing:

        a_queryset = ModelA.objects.all()
        another_queryset = ModelB.objects.filter.(by_something=True)
        yet_another_queryset =
ModelC.objects.exclude(by_something_else=False)

        from itertools import chain
        big_honking_list = list(chain(a_queryset, another_queryset,
yet_another_queryset))
        big_honking_list.sort(key=lambda x: x.updated)
        big_honking_list.reverse()

As to your last question, that is easy if you're doing a list.sort()
-- just expose a method on each model that returns a sortable value
that is consistent across all the models. (Or write a dedicated
function to use instead of the lambda above, whichever makes more
sense.)

On Oct 26, 7:25 am, 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?

-- 
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.

Reply via email to