I set up an ordering='ordering_number' Meta attribute to my Django model, thinking that Django will use it when comparing instances. (ordering_number is an IntegerField in my model.)
For example, if I have an instance a with ordering_number = 4 and an instance b with ordering_number = 7, I’d expect that a < b would be True. However, I tested it, and it didn’t seem to work. I did not understand according to which logic a < b would come out as True.
Does anyone know? Why doesn’t Django uses ordering for element comparisons?
From the documentation:
So the reason your comparisons aren’t working is because they’re not designed that way. Define
__lt__()et alia to define ordering of instances.