Django Rest Framework filtering calculated model property

前端 未结 3 1331
野趣味
野趣味 2021-02-13 14:17

Sorry for a newbie question. I have a following model:

class WeightSlip(models.Model):

    grossdate = models.DateTimeField(auto_now=False, auto_now_add=False)
         


        
3条回答
  •  终归单人心
    2021-02-13 14:32

    Note that if you're using the latest version of django-filter, Filter.method takes 4 arguments, like so:

    def filter_slipdate(self, queryset, name, value):
        if value:
            queryset = queryset.annotate(slipdate=Case(When(grossdate__gt=F('taredate'), then=F('grossdate')), default=F('taredate')).filter(slipdate=value)
        return queryset
    

    ```

提交回复
热议问题