aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site
diff options
context:
space:
mode:
Diffstat (limited to 'pydis_site')
-rw-r--r--pydis_site/apps/api/migrations/0057_create_new_filterlist_model.py4
-rw-r--r--pydis_site/apps/api/models/bot/filter_list.py11
-rw-r--r--pydis_site/apps/api/serializers.py15
3 files changed, 15 insertions, 15 deletions
diff --git a/pydis_site/apps/api/migrations/0057_create_new_filterlist_model.py b/pydis_site/apps/api/migrations/0057_create_new_filterlist_model.py
index 44025ee8..b5398568 100644
--- a/pydis_site/apps/api/migrations/0057_create_new_filterlist_model.py
+++ b/pydis_site/apps/api/migrations/0057_create_new_filterlist_model.py
@@ -25,9 +25,5 @@ class Migration(migrations.Migration):
('comment', models.TextField(help_text="Optional comment on this entry.", null=True)),
],
bases=(pydis_site.apps.api.models.mixins.ModelReprMixin, models.Model),
- ),
- migrations.AddConstraint(
- model_name='filterlist',
- constraint=models.UniqueConstraint(fields=('content', 'type'), name='unique_filter_list'),
)
]
diff --git a/pydis_site/apps/api/models/bot/filter_list.py b/pydis_site/apps/api/models/bot/filter_list.py
index d279e137..5961aed7 100644
--- a/pydis_site/apps/api/models/bot/filter_list.py
+++ b/pydis_site/apps/api/models/bot/filter_list.py
@@ -28,14 +28,3 @@ class FilterList(ModelTimestampMixin, ModelReprMixin, models.Model):
help_text="Optional comment on this entry.",
null=True
)
-
- class Meta:
- """Metaconfig for this model."""
-
- # This constraint ensures only one filterlist with the
- # same content can exist. 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_filter_list'),
- ]
diff --git a/pydis_site/apps/api/serializers.py b/pydis_site/apps/api/serializers.py
index 8fd40da7..54bb8a5d 100644
--- a/pydis_site/apps/api/serializers.py
+++ b/pydis_site/apps/api/serializers.py
@@ -113,6 +113,21 @@ class FilterListSerializer(ModelSerializer):
model = FilterList
fields = ('id', 'created_at', 'updated_at', 'type', 'allowed', 'content', 'comment')
+ # This validator ensures only one filterlist with the
+ # same content can exist. 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.
+ validators = [
+ UniqueTogetherValidator(
+ queryset=FilterList.objects.all(),
+ fields=['content', 'type'],
+ message=(
+ "A filterlist for this item already exists. "
+ "Please note that you cannot add the same item to both allow and deny."
+ )
+ ),
+ ]
+
class InfractionSerializer(ModelSerializer):
"""A class providing (de-)serialization of `Infraction` instances."""