added custom filter with tag support to products
This commit is contained in:
@@ -3,9 +3,15 @@ from products.models import Product
|
||||
|
||||
|
||||
class ProductTagFilter(django_filters.FilterSet):
|
||||
tags = django_filters.CharFilter(field_name='tags.name', lookup_expr='iexact')
|
||||
tags = django_filters.CharFilter(method='tag_filter')
|
||||
|
||||
class Meta:
|
||||
model = Product
|
||||
fields = ['name',]
|
||||
fields = ['name', 'tags']
|
||||
|
||||
def tag_filter(self, queryset, name, value):
|
||||
if name == 'tags':
|
||||
return queryset.filter(tags=value)
|
||||
return []
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user