Browse Source

pref: 修改创建 platform

pull/8873/head
ibuler 2 years ago
parent
commit
bb6b9e6f6e
  1. 2
      apps/perms/apps.py
  2. 4
      apps/users/serializers/group.py
  3. 4
      utils/generate_fake_data/resources/assets.py

2
apps/perms/apps.py

@ -10,5 +10,5 @@ class PermsConfig(AppConfig):
def ready(self): def ready(self):
super().ready() super().ready()
from . import signal_handlers # from . import signal_handlers
from . import notifications from . import notifications

4
apps/users/serializers/group.py

@ -47,7 +47,5 @@ class UserGroupSerializer(BulkOrgResourceModelSerializer):
@classmethod @classmethod
def setup_eager_loading(cls, queryset): def setup_eager_loading(cls, queryset):
""" Perform necessary eager loading of data. """ """ Perform necessary eager loading of data. """
queryset = queryset.prefetch_related( queryset = queryset.prefetch_related('users').annotate(users_amount=Count('users'))
Prefetch('users', queryset=User.objects.only('id'))
).annotate(users_amount=Count('users'))
return queryset return queryset

4
utils/generate_fake_data/resources/assets.py

@ -34,8 +34,8 @@ class PlatformGenerator(FakeDataGenerator):
tp = choice(self.category_type[category].choices) tp = choice(self.category_type[category].choices)
data = { data = {
'name': forgery_py.name.company_name(), 'name': forgery_py.name.company_name(),
'category': choice(self.categories), 'category': category,
'type': tp 'type': tp[0]
} }
platforms.append(Platform(**data)) platforms.append(Platform(**data))
Platform.objects.bulk_create(platforms, ignore_conflicts=True) Platform.objects.bulk_create(platforms, ignore_conflicts=True)

Loading…
Cancel
Save