Untitled
unknown
python
3 years ago
536 B
2
Indexable
Never
class RecipeFilter(django_filters.FilterSet): tags = django_filters.CharFilter(field_name='tags__slug') is_favorited = django_filters.BooleanFilter( field_name='favorite_recipe', method='filter_is_favorited', ) def filter_is_favorited(self, queryset, name, value): lookup = '__'.join([name, 'isnull']) return queryset.filter(**{lookup: True}) class Meta: model = Recipe fields = ( 'author', 'tags', 'is_favorited', )