Hello Django Community,
Im stuck on something that I feel should be pretty simple. I have two models Request and RequestComment, naturally RequestComment foreign keys to Request. I have a scenario where i need to base some logic in a view related to Requests off of an attribute in the most recent RequestComment on a Request and im trying to see if I can add the most recent RequestComment for reach Request to a request queryset so that i can use this in a table.
sample request queryset:
q1 = Request.objects.filter("status="New", created_at__lt="timezone.now() - timdelta(days=1))
I would like to add the most recent comment object to each result this query, effectively adding the result of querying RequestComment for the related Request in each row of q1 and filtering by -created_at and calling .first() and adding that as like request_latest_comment or similar. Im looking to add the whole object, as RequestComment also foreign keys to user which i need some info there too.
Is this something that can be done with annotate? If someone is able to provide either a suggestion or a link to a kb/forum where similar has been done, id greatly appreciate it.
Best,
Josh