From e8a32c717babee132626d6574f7ca706338739dc Mon Sep 17 00:00:00 2001 From: Leon Sandøy Date: Wed, 15 Jul 2020 15:32:23 +0200 Subject: Add a UniqueConstraint to prevent duplicates. https://github.com/python-discord/site/issues/305 --- pydis_site/apps/api/models/bot/allowlist.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'pydis_site/apps/api/models') diff --git a/pydis_site/apps/api/models/bot/allowlist.py b/pydis_site/apps/api/models/bot/allowlist.py index b0aea066..fc57ef32 100644 --- a/pydis_site/apps/api/models/bot/allowlist.py +++ b/pydis_site/apps/api/models/bot/allowlist.py @@ -24,3 +24,16 @@ class AllowList(ModelTimestampMixin, ModelReprMixin, models.Model): content = models.TextField( help_text="The data to add to the allowlist." ) + + class Meta: + """Metaconfig for this model.""" + + db_table = 'allow_list' + + # This constraint ensures only one allowlist with the same content + # can exist per type.This means that we cannot have both an allow + # and a deny for the same item, and we cannot have duplicates of the + # same item. + constraints = [ + models.UniqueConstraint(fields=['content', 'type'], name='unique_allowlist'), + ] -- cgit v1.2.3