On Jun 30, 1:31 am, elliot <
offonoffoffon...@gmail.com> wrote:
> Sorry about the vague title. Its hard for me to summarize this in one
> short sentence.
> Lets say I have two models (using pseudo code):
>
> Book(model.Model):
> name = charfield()
>
> Transaction(model.Model):
> start_date = DateTimeField()
> item = ManytoMany(Book)
> recipient = CharField()
>
> Now for every book, I want to know the recipient of only the most
> recent transaction. I can get the start date of the most recent
> transaction for each book with
>
> Book.objects.annotate(mostrecent = Max('transaction__start_date'))
>
> but what I would like is the pk of that transaction, so I can get more
> information about it.
you may want to read the doc for QuerySet.extra. Also, sometimes it's