aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site/apps/api/models
diff options
context:
space:
mode:
authorGravatar Leon Sandøy <[email protected]>2020-07-15 15:32:23 +0200
committerGravatar Leon Sandøy <[email protected]>2020-07-15 15:32:23 +0200
commite8a32c717babee132626d6574f7ca706338739dc (patch)
treee9ab3b0b1b596f1021ab7275d184b60273fc38a2 /pydis_site/apps/api/models
parentAdd a migration for the new AllowList model. (diff)
Add a UniqueConstraint to prevent duplicates.
https://github.com/python-discord/site/issues/305
Diffstat (limited to 'pydis_site/apps/api/models')
-rw-r--r--pydis_site/apps/api/models/bot/allowlist.py13
1 files changed, 13 insertions, 0 deletions
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'),
+ ]