It is required to sort objects, by fields in other models.

Basic model <- (several document objects1 (sorting by date field))

Basic model <- (several document objects2 (sorting by date field)).

It is required to select the maximum dates in the objects of documents1 and documents2, then select the maximum date between documents1 and documents2, and sort according to it in the set of basic models

Example:

new_docs_tasks.annotate(gs=Max('owner_process__request__requestdocument__doc__registered'), guag=Min('owner_process__request__gsrequestdata__gsdocument__doc__registered')) 

In this request, I selected max dates for documents1 ( gs ) and documents1 ( guag ), now how can I choose the maximum date between gs and guag to shove order_by ? there is a solution through sort , but you have to convert to a list , it does not work very quickly, considering that it will still have to be folded with another set

  • Schematically filter (gs__lte = Max ('owner_process__request__requestdocument__doc__registered'), gs__gte> Min ...). Order_by ("gs") So doesn't it work? - Igor

0