[Answered ]-Getting the most recent 'created' row (spaning tables)

2👍

Assuming you have a view where you receive a potter id:

ordered_sculptures = Sculpture.objects.filter(potter=potter).order_by('-created') 
ordered_vases = Vase.objects.filter(potter=potter).order_by('-created')

EDIT: I may have misread something, so if you want the latest using the querysets, you can just reference the first element of each queryset (if they exist):

latest = ordered_sculptures[0]

Same applies for vases.

Reference: django order_by in the docs

Another approach, if you defined your default ordering for those querysets, is the reverse method:

latest = Sculpture.objects.filter(potter=potter).reverse()[0]

Leave a comment