1
0
Fork 0
mirror of https://github.com/Findus23/acronomy.git synced 2024-09-19 15:33:45 +02:00
acronomy/acros/models/Weblink.py

24 lines
662 B
Python
Raw Normal View History

2020-06-01 11:03:21 +02:00
from urllib.parse import urlparse
from django.db import models
from simple_history.models import HistoricalRecords
from acros.models import Acronym, Host
class Weblink(models.Model):
acronym = models.ForeignKey(Acronym, on_delete=models.CASCADE, related_name="links")
url = models.URLField()
host = models.ForeignKey(Host, on_delete=models.CASCADE, editable=False)
history = HistoricalRecords()
def __str__(self):
return self.url
def save(self, *args, **kwargs):
uri = urlparse(self.url)
self.host, created = Host.objects.get_or_create(host=uri.hostname)
super(Weblink, self).save(*args, **kwargs)