S
S
snowhod2016-11-10 13:46:07
Django
snowhod, 2016-11-10 13:46:07

How to sort by ManyToManyField field?

How to sort a selection from the database by the number of links in a ManyToManyField type field using standard django tools?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
iegor, 2016-11-10
@snowhod

.annotate(Count('m2m_field')).order_by('m2m_field__count')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question