From e4e2c788a98a01277c64e5d1d30677a3839c3985 Mon Sep 17 00:00:00 2001 From: Schylar Utley Date: Wed, 20 Jan 2021 21:42:24 -0600 Subject: [PATCH] Update 290_webhooks.py Move to a more standard method of object handling --- startup_scripts/290_webhooks.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/startup_scripts/290_webhooks.py b/startup_scripts/290_webhooks.py index 8fc924e..f6d480b 100644 --- a/startup_scripts/290_webhooks.py +++ b/startup_scripts/290_webhooks.py @@ -20,8 +20,7 @@ for hook in webhooks: obj_types = hook.pop('object_types') obj_type_ids = [ get_content_type_id(obj) for obj in obj_types ] if obj_type_ids is not None: - webhook = Webhook(**hook) - if not Webhook.objects.filter(name=webhook.name): - webhook.save() + webhook, created = Webhook.objects.get_or_create(**hook) + if created: webhook.content_types.set(obj_type_ids) print("🖥️ Created Webhook {0}".format(webhook.name))