aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site/apps/api/models
diff options
context:
space:
mode:
authorGravatar Numerlor <[email protected]>2020-08-03 22:16:27 +0200
committerGravatar Numerlor <[email protected]>2020-08-03 22:16:27 +0200
commit6516eff584065ed121109b7874cb080f72c5e3cc (patch)
tree2f8e172e189ea0b333ce5848c1dea264d148811f /pydis_site/apps/api/models
parentFix bad migration 0059 (diff)
Add a validator for package names.
Package names are used for stats in the bot and are restricted to the a-z_ char set, a validator is added to accommodate this restriction at the site admin side.
Diffstat (limited to 'pydis_site/apps/api/models')
-rw-r--r--pydis_site/apps/api/models/bot/documentation_link.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/pydis_site/apps/api/models/bot/documentation_link.py b/pydis_site/apps/api/models/bot/documentation_link.py
index 5a46460b..f77d6f38 100644
--- a/pydis_site/apps/api/models/bot/documentation_link.py
+++ b/pydis_site/apps/api/models/bot/documentation_link.py
@@ -1,3 +1,4 @@
+from django.core.validators import RegexValidator
from django.db import models
from pydis_site.apps.api.models.mixins import ModelReprMixin
@@ -9,6 +10,12 @@ class DocumentationLink(ModelReprMixin, models.Model):
package = models.CharField(
primary_key=True,
max_length=50,
+ validators=(
+ RegexValidator(
+ regex=r"^[a-z_]+$",
+ message="Package names can only consist of lowercase a-z letters and underscores."
+ ),
+ ),
help_text="The Python package name that this documentation link belongs to."
)
base_url = models.URLField(