aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pydis_site/apps/api/migrations/0057_create_new_allowlist_model.py (renamed from pydis_site/apps/api/migrations/0057_allowlist.py)8
-rw-r--r--pydis_site/apps/api/models/bot/allowlist.py13
2 files changed, 21 insertions, 0 deletions
diff --git a/pydis_site/apps/api/migrations/0057_allowlist.py b/pydis_site/apps/api/migrations/0057_create_new_allowlist_model.py
index 7d815e91..45650d86 100644
--- a/pydis_site/apps/api/migrations/0057_allowlist.py
+++ b/pydis_site/apps/api/migrations/0057_create_new_allowlist_model.py
@@ -26,4 +26,12 @@ class Migration(migrations.Migration):
},
bases=(pydis_site.apps.api.models.mixins.ModelReprMixin, models.Model),
),
+ migrations.AlterModelTable(
+ name='allowlist',
+ table='allow_list',
+ ),
+ migrations.AddConstraint(
+ model_name='allowlist',
+ constraint=models.UniqueConstraint(fields=('content', 'type'), name='unique_allowlist'),
+ )
]
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'),
+ ]