From f0c9c2b1ad3afcebf5c2ce402539d498e7889d12 Mon Sep 17 00:00:00 2001 From: ibuler Date: Mon, 22 Aug 2022 15:23:28 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E6=B7=BB=E5=8A=A0=E7=94=9F=E6=88=90=20?= =?UTF-8?q?platform?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/generate_fake_data/generate.py | 3 ++- utils/generate_fake_data/resources/assets.py | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/utils/generate_fake_data/generate.py b/utils/generate_fake_data/generate.py index 5fdfddc5c..a1e82cf7a 100644 --- a/utils/generate_fake_data/generate.py +++ b/utils/generate_fake_data/generate.py @@ -12,7 +12,7 @@ sys.path.insert(0, APPS_DIR) os.environ.setdefault("DJANGO_SETTINGS_MODULE", "jumpserver.settings") django.setup() -from resources.assets import AssetsGenerator, NodesGenerator +from resources.assets import AssetsGenerator, NodesGenerator, PlatformGenerator from resources.users import UserGroupGenerator, UserGenerator from resources.perms import AssetPermissionGenerator from resources.terminal import CommandGenerator, SessionGenerator @@ -20,6 +20,7 @@ from resources.terminal import CommandGenerator, SessionGenerator resource_generator_mapper = { 'asset': AssetsGenerator, + 'platform': PlatformGenerator, 'node': NodesGenerator, 'user': UserGenerator, 'user_group': UserGroupGenerator, diff --git a/utils/generate_fake_data/resources/assets.py b/utils/generate_fake_data/resources/assets.py index 7144b1b5c..6e1ad8cab 100644 --- a/utils/generate_fake_data/resources/assets.py +++ b/utils/generate_fake_data/resources/assets.py @@ -30,9 +30,12 @@ class PlatformGenerator(FakeDataGenerator): def do_generate(self, batch, batch_size): platforms = [] for i in batch: + category = choice(self.categories) + tp = choice(self.category_type[category].choices) data = { 'name': forgery_py.name.company_name(), - 'category': '' + 'category': choice(self.categories), + 'type': tp } platforms.append(Platform(**data)) Platform.objects.bulk_create(platforms, ignore_conflicts=True)