I am stuck with ordering on calculated field.
Let's say my model looks like:
class Foo(models.Model):
fieldA = models.CharField()
fieldB = models.CharField()
@property
def calculatedField(self):
return someFunc(fieldA)
Now I wan't my ViewSet
to be able to apply ordering to calculatedField
, so I have following code in there:
class SomeViewSet(mixins.ListModelMixin, viewsets.GenericViewSet):
...
ordering_fields = ('calculatedField',)
...
But when I try to apply to order using query parameters like
Method GET /someEndpoint/?ordering=calculatedField
I get the following error
Cannot resolve keyword 'calculatedField' into the field. Choices are: ...
Is there a way to apply to order to calculatedField? Thanks