From 7f42e59714b9c3e48da0480df4b2b9d62ee067f6 Mon Sep 17 00:00:00 2001 From: xinwen Date: Fri, 5 Mar 2021 14:29:54 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=81=87=E6=95=B0=E6=8D=AE=E8=84=9A=E6=9C=AC=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/generate_fake_data/resources/assets.py | 8 ++------ utils/generate_fake_data/resources/base.py | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/utils/generate_fake_data/resources/assets.py b/utils/generate_fake_data/resources/assets.py index 4c5cbba93..4279e6c5a 100644 --- a/utils/generate_fake_data/resources/assets.py +++ b/utils/generate_fake_data/resources/assets.py @@ -65,13 +65,9 @@ class AssetsGenerator(FakeDataGenerator): self.nodes_id = list(Node.objects.all().values_list('id', flat=True)) def set_assets_nodes(self, assets): - assets_id = [asset.id for asset in assets] - objs = [] - for asset_id in assets_id: + for asset in assets: nodes_id_add_to = random.sample(self.nodes_id, 3) - objs_add = [Asset.nodes.through(asset_id=asset_id, node_id=nid) for nid in nodes_id_add_to] - objs.extend(objs_add) - Asset.nodes.through.objects.bulk_create(objs, ignore_conflicts=True) + asset.nodes.add(*nodes_id_add_to) def do_generate(self, batch, batch_size): assets = [] diff --git a/utils/generate_fake_data/resources/base.py b/utils/generate_fake_data/resources/base.py index ba45f602b..723baa6dd 100644 --- a/utils/generate_fake_data/resources/base.py +++ b/utils/generate_fake_data/resources/base.py @@ -15,7 +15,7 @@ class FakeDataGenerator: seed() def switch_org(self, org_id): - o = Organization.get_instance(org_id, default=True) + o = Organization.get_instance(org_id, default=Organization.default()) if o: o.change_to() print('Current org is: {}'.format(o))