I have this model:
class Auction(models.Model):
start_price = models.IntegerField()
price_step = models.IntegerField()
finish_time = models.DateTimeField()
@property
def is_active(self):
return self.finish_time > timezone.now()
I also have this in my serializer class:
class AuctionSerializer(serializers.ModelSerializer):
is_active = serializers.ReadOnlyField()
class Meta:
model = Auction
fields = '__all__'
And this in my view class:
class AuctionViewSet(ModelViewSet):
queryset = Auction.objects.all()
serializer_class = AuctionSerializer
filter_backends = (DjangoFilterBackend,)
filter_fields = ('is_active',)
But it throws "'Meta.fields' contains fields that are not defined on this FilterSet: is_active". I can use it as a serializer field but I can't do filtering by this field. How do I properly implement filtering by model property not just model field?