Skip to content

Commit

Permalink
feat: update template group list filter with name (#2621)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhu327 authored Apr 16, 2024
1 parent 895bbb9 commit b3d7030
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions saas/backend/apps/template/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,20 @@
"""
from django_filters import rest_framework as filters

from backend.apps.group.models import Group
from backend.apps.template.models import PermTemplate, PermTemplatePolicyAuthorized


class TemplateMemberFilter(filters.FilterSet):
types = filters.CharFilter(method="types_filter", label="用户名")
name = filters.CharFilter(method="name_filter", label="用户组名")

class Meta:
model = PermTemplatePolicyAuthorized
fields = ["types"]
fields = ["name"]

def types_filter(self, queryset, name, value):
types = value.split(",")
if types:
return queryset.filter(subject_type__in=types)
return queryset
def name_filter(self, queryset, name, value):
group_ids = list(Group.objects.filter(name__icontains=value).values_list("id", flat=True))
return queryset.filter(subject_id__in=group_ids)


class TemplateFilter(filters.FilterSet):
Expand Down

0 comments on commit b3d7030

Please sign in to comment.