Tuesday, September 13, 2011

Re: Alter the list of fields returned by a queryset without turning them into strings?

So, how I actually solved it was even a bit different:

Document.objects.filter(documentType=1, event__eventType=1).annotate(Max('event__start_date')).order_by('event__start_date__max')

I had to use the Max function because the relationship is actually a many to many. Even if it was just a standard foreign key this is still an option, and it eliminates the problem of re-querying if you later decide to use other fields. 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/LJZowJhdGbkJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate