add external links
This commit is contained in:
parent
7b21d9d612
commit
8ed39690f1
5 changed files with 98 additions and 1 deletions
|
@ -205,3 +205,33 @@ class Lead(models.Model):
|
|||
|
||||
def __str__(self):
|
||||
return f"{self.name} - {self.company} ({self.service})"
|
||||
|
||||
|
||||
class ExternalLink(models.Model):
|
||||
service = models.ForeignKey(
|
||||
Service, on_delete=models.CASCADE, related_name="external_links"
|
||||
)
|
||||
url = models.URLField()
|
||||
description = models.CharField(max_length=200)
|
||||
order = models.IntegerField(default=0)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ["order", "description"]
|
||||
verbose_name = "External Link"
|
||||
verbose_name_plural = "External Links"
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.description} ({self.url})"
|
||||
|
||||
def clean(self):
|
||||
from django.core.validators import URLValidator
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
# Validate URL
|
||||
validate = URLValidator()
|
||||
try:
|
||||
validate(self.url)
|
||||
except ValidationError:
|
||||
raise ValidationError({"url": "Enter a valid URL."})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue