From 590889072607974581ee403ecfb70286f039763a Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 25 Oct 2020 22:07:11 +1100 Subject: [PATCH] Create setting if it does not exist --- InvenTree/common/models.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/InvenTree/common/models.py b/InvenTree/common/models.py index 3150dad2a4..0d3afbe226 100644 --- a/InvenTree/common/models.py +++ b/InvenTree/common/models.py @@ -204,9 +204,14 @@ class InvenTreeSetting(models.Model): try: setting = InvenTreeSetting.objects.filter(key__iexact=key).first() - return setting except (InvenTreeSetting.DoesNotExist): - return None + # Create the setting if it does not exist + setting = InvenTreeSetting.create( + key=key, + value=InvenTreeSetting.get_default_value(key) + ) + + return setting @classmethod def get_setting_pk(cls, key):