0

I am trying to order QuerySet by a method defined in my class

Class EgzampleClass(models.Model):
    somefield =  models.ForeignKey(User)
    otherfield = models.CharField()

    @property
    def mymethod(self):
        countsth=1
        return countsth

I would like to do a thing like this

EgzampleClass.objects.all().order_by('mymethod')

Does anyone have an idea how can I do it? Thanks in advance

alis01
  • 169
  • 1
  • 3
  • 11
  • Does this answer your question? [Sorting a Django QuerySet by a property (not a field) of the Model](https://stackoverflow.com/questions/4175749/sorting-a-django-queryset-by-a-property-not-a-field-of-the-model) – kamilyrb Feb 20 '20 at 16:31
  • Yes, thanks a lot. I was looking for an answer, no idea why I didn't find it, thank you for help :) – alis01 Feb 21 '20 at 12:15

0 Answers0