The following model is available:
class Departments(Document): _id = fields.ObjectIdField() name = fields.StringField(blank=True, null=True) department_id = fields.StringField(blank=True, null=True) # Added list_of_users = fields.ListField(blank=True, null=True) list_of_workstations = fields.ListField(blank=True, null=True) As you can see, list_of_users and list_of_workstations are lists of objects.
I wrote a code on Python that pulls all the data out of the database, puts it into the dictionary, and performs sorting, but this method works too slowly.
How can I sort the Департаменты directly into the database by the number of list_of_users or list_of_workstations or by the ratio of list_of_users/list_of_workstations , something like:
departments = DepartmentStats.objects.order_by(len(list_of_users)).dsc or
departments = DepartmentStats.objects.order_by(len(list_of_users)/len(list_of_workstations)).dsc ?