Model1(models.Model):
name = models.CharField(max_length=30)
Model2(models.Model):
model1 = models.ManyToManyField(FontClass)
res = Model1.objects.all().filter(....).order_by('model1__name....???')
How can sort the result by more complex condition such whether or not model1__name
has an underscore in its name? For example, Model1.objects.all().filter(....)
returns the following names:
aaa_bbb
aaaccc
aaa_ttt
aaa_ddd
ggggg
yyy_cccc
zzz_kkk
dddd
After sorting it should be:
aaa_bbb
zzz_kkk
aaa_ddd
aaa_ttt
yyy_cccc
aaaccc
ggggg
dddd
First the ones with the underscore in their names, then - without it.
Note that condition is just an example for I want to be to sort by even complex ones, I just want to get how to do that.