0👍
✅
You can also annotate the latest timestamp to your query and then query against its state. Something like this should do the trick:
from django.db.models import F, Max
Camera.objects.annotate(latest_timestamp=Max('timestamp__datetime')).filter(latest_timestamp=F('timestamp__datetime'), timestamp__state=False)
1👍
You need to use Q object for this query. Please do some study about Django Q object.
https://docs.djangoproject.com/en/1.10/topics/db/queries/#complex-lookups-with-q-objects
Source:stackexchange.com