how are you? :)
My question is about using django RF ViewSets, RF Filters, over annotated fields with custom Object Managers.
So I've got this class
class SomeClass(models.Model):
this_does_not_matter = models.CharField(max_length=50)
objects = SomeClassManager()
with some manager with this shape
class SomeClassManager(models.Manager):
def full_objs(self):
qs = self.all()
qs = qs.annotate(
some_annotated_field=Count('this_dont_matter_either')
)
return qs
and finally, this viewSet
from rest_framework.viewsets import ModelViewSet
from rest_framework.filters import SearchFilter
...
class SomeClassViewSet(ModelViewSet):
queryset = SomeClass.objects.full_objs()
serializer_class = SomeClassSerializer
filter_backends = (SearchFilter,)
search_fields = ('some_annotated_field',)
and I get
SomeClass has no field named 'some_annotated_field'
even though i do get that field when asking for it to the api.
Question is: how do I get to search on some_annotated_field