优化: queryset 当进入if判断,for循环,print等,会直接查询数据库bug

pull/79/head
李强 2022-11-09 10:13:11 +08:00
parent e9aef6b744
commit 2c86ad0450
3 changed files with 5 additions and 6 deletions

View File

@ -108,10 +108,8 @@ class SystemConfigChinldernSerializer(CustomModelSerializer):
def get_chinldern(self, instance):
queryset = SystemConfig.objects.filter(parent=instance)
if queryset:
serializer = SystemConfigSerializer(queryset, many=True)
return serializer.data
return None
class Meta:
model = SystemConfig

View File

@ -231,7 +231,8 @@ class UserViewSet(CustomModelViewSet):
update_serializer_class = UserUpdateSerializer
# filter_fields = ["name", "username", "gender", "is_active", "dept", "user_type"]
filter_fields = {
"name": ["icontains"],
"name": ["exact"],
"mobile": ["exact"],
"username": ["exact"],
"gender": ["icontains"],
"is_active": ["icontains"],

View File

@ -154,7 +154,7 @@ def get_verbose_name(queryset=None, view=None, model=None):
:return:
"""
try:
if queryset and hasattr(queryset, 'model'):
if queryset is not None and hasattr(queryset, 'model'):
model = queryset.model
elif view and hasattr(view.get_queryset(), 'model'):
model = view.get_queryset().model