Browse Source

add validation

main
xenua 2 years ago
parent
commit
dcfe64a0a7
Signed by: xenua
GPG Key ID: 8F93B68BD37255B8
  1. 10
      leftists/models.py

10
leftists/models.py

@ -1,3 +1,4 @@ @@ -1,3 +1,4 @@
from django.core.exceptions import ValidationError
from django.db import models
from django.utils.translation import gettext_lazy as _
from xenua.django.models import RandomSlugPKMixin
@ -18,12 +19,19 @@ class Domain(models.Model): @@ -18,12 +19,19 @@ class Domain(models.Model):
return cls.objects.get(fqdn__iexact=r.get_host())
def validate_location(loc):
if "/" in loc:
raise ValidationError(
_('location must not contain a slash')
)
class ShortLink(RandomSlugPKMixin, models.Model):
class Meta:
unique_together = ('domain', 'location')
domain = models.ForeignKey(Domain, related_name='links', on_delete=models.CASCADE)
location = models.CharField(_("short link"), max_length=100)
location = models.CharField(_("short link"), max_length=100, validators=[validate_location])
to = models.URLField(_("redirect to"), max_length=2500)
click_count = models.IntegerField(default=0)

Loading…
Cancel
Save