Re: getting objects unique in several ways (annotate?)
Michal's answer does not work. For each book, I want fields from one
of its Transactions. .values('pk') gives the book's pk (no
relationship to Transaction) and .values('transaction__recipient')
does not work either.
I dont know squat about writing queries in sql, so extra doesn't help
me. When coming at it from the other side of the relationship, I
can't see how to get just one transaction for each book. Doing it the
above way, the database finds the one transaction per book, but wont
tell me the pk or any other information about that transaction.
Coming from the other side, it would be easy to order the transactions
by book__pk and then date, and then use a foor loop to grab the most
recent transaction for each book.
Using the for loop, I'll need to make sure to not hit the db for every
iteration. Otherwise, I dont think this would be intolerably slow.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
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