Features: 1) Add children_present BooleanFilter to CategoryFilter for filtering presence of children;
Fixes: None; Extra: 1) Implement `filter_children_presence` method to support the new filter;
This commit is contained in:
parent
64f00d74c0
commit
33e557e693
1 changed files with 8 additions and 0 deletions
|
|
@ -323,6 +323,8 @@ class CategoryFilter(FilterSet):
|
|||
parent_uuid = CharFilter(method="filter_parent_uuid", label=_("Parent"))
|
||||
slug = CharFilter(field_name="slug", lookup_expr="exact", label=_("Slug"))
|
||||
tags = CaseInsensitiveListFilter(field_name="tags__tag_name", label=_("Tags"))
|
||||
children_present = BooleanFilter(method="filter_children_presence", field_name="children_present",
|
||||
label=_("children present"))
|
||||
|
||||
order_by = OrderingFilter(
|
||||
fields=(
|
||||
|
|
@ -336,6 +338,12 @@ class CategoryFilter(FilterSet):
|
|||
model = Category
|
||||
fields = ["uuid", "name", "parent_uuid", "slug", "tags"]
|
||||
|
||||
def filter_children_presence(self, queryset, _name, value):
|
||||
if value:
|
||||
return queryset.filter(children__isnull=False)
|
||||
else:
|
||||
return queryset.filter(children__isnull=True)
|
||||
|
||||
def filter_parent_uuid(self, queryset, _name, value):
|
||||
if value in ("", "null", "None"):
|
||||
return queryset.filter(parent=None)
|
||||
|
|
|
|||
Loading…
Reference in a new issue