39👍
✅
Thanks to Robert’s answer i was able to find Greatest
class of Django.
The following works:
from django.db.models.functions import Greatest
Client.objects.annotate(
latest_activity_at=Greatest('uploaded_photo_at', 'uploaded_document_at')
).order_by('latest_activity_at')
2👍
Hi you can use django query extra function
qs = Client.objects.extra(select={'output_field':
'GREATEST(uploaded_photo_at, uploaded_document_at)'})
.order_by('latest_activity_at')
This will return max value two fileds
- [Django]-Django equivalent of PHP's form value array/associative array
- [Django]-Django: Model Form "object has no attribute 'cleaned_data'"
- [Django]-Django – [Errno 111] Connection refused
Source:stackexchange.com