There is a Clan model that has a CharField (string) title field. I need to sort all the objects of this model according to this field, but according to the given condition - it is necessary to sort the objects according to the frequency of meeting this substring in the title (title) of the clan (Clan)
The following method sorts by default, as I remember in lexicographical order:
Clan.objects.order_by('title') I need to sort all models of the clan by the frequency of meeting a given substring in them -> in this case, let this string be 'clan' . That is, it should be something like this (but it does not work, in this case a double underderskor indicates sorting by the model field, after which it is used - and we mean the line)
Clan.objects.order_by("title__contains='clan'") I would also like to know how to sort / filter clan objects by the absence of a given substring in them
['Clan spam clan eggs clan', 'clan qwerty clan', 'clan foo', 'bar']? - Sergey Gornostaev