You can try the following:
max(Model1.objects.aggregate(max_date = Max('created_datetime'))['max_date'], Model2.objects.aggregate(max_date = Max('created_datetime'))['max_date'])
This doesn't do a UNION
, but you get what you require.
N.B. : max
is a python function and Max
a django models function (
from django.db.models.aggregates import Max
has to be used for Max
).
You can also do something like the following:
max(Model1.objects.all().values_list('created_datetime',flat=True).extend(Model2.objects.all().values_list('created_datetime',flat=True)))
Here, aggregation hasn't been used (and so, the Max
not used). max
of python has still been used and anything like UNION of sql is still not seen, but, joining of 2 lists has been used.
You can see what suits you bests or some other 3rd solution if any drops by. I would really love to even know a better solution than the above. :)
You could also refer the link to see if it helps you.