aboutsummaryrefslogtreecommitdiffstats
path: root/brevisurl/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'brevisurl/models.py')
-rw-r--r--brevisurl/models.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/brevisurl/models.py b/brevisurl/models.py
index 0a583ad..9ade639 100644
--- a/brevisurl/models.py
+++ b/brevisurl/models.py
@@ -13,7 +13,7 @@ log = logging.getLogger(__name__)
class ShortUrl(models.Model):
"""Model that represents shortened url."""
- original_url = models.CharField(max_length=200, null=False, blank=False)
+ original_url = models.URLField(max_length=200, null=False, blank=False)
original_url_hash = models.CharField(max_length=64, null=False, blank=False)
shortened_url = models.URLField(max_length=200, null=False, blank=False, unique=True)
backend = models.CharField(max_length=200, null=False, blank=False)
@@ -33,9 +33,14 @@ class ShortUrl(models.Model):
def clean(self):
url_validator = URLValidator()
try:
+ url_validator(self.original_url)
+ except ValidationError:
+ log.exception('ShortUrl.original_url "%s" is not valid URL', self.original_url)
+ raise
+ try:
url_validator(self.shortened_url)
except ValidationError:
- log.exception('ShortUrl.shortened_url is not valid URL')
+ log.exception('ShortUrl.shortened_url "%s" is not valid URL', self.shortened_url)
raise
return super(ShortUrl, self).clean()