Updates models
This commit is contained in:
@ -4,7 +4,7 @@ import sys
|
||||
|
||||
from .book import Book, Work, Edition, BookDataModel
|
||||
from .author import Author
|
||||
from .link import Link, FileLink
|
||||
from .link import Link, FileLink, LinkDomain
|
||||
from .connector import Connector
|
||||
|
||||
from .shelf import Shelf, ShelfBook
|
||||
|
@ -1,4 +1,6 @@
|
||||
""" outlink data """
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
@ -12,12 +14,25 @@ class Link(ActivitypubMixin, BookWyrmModel):
|
||||
"""a link to a website"""
|
||||
|
||||
url = fields.URLField(max_length=255, activitypub_field="href")
|
||||
domain = models.ForeignKey(
|
||||
"LinkDomain", on_delete=models.PROTECT, null=True, blank=True
|
||||
)
|
||||
|
||||
activity_serializer = activitypub.Link
|
||||
reverse_unfurl = True
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""link name via the assocaited domain"""
|
||||
return self.domain.name
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
"""create a link"""
|
||||
# get or create the associated domain
|
||||
if not self.domain:
|
||||
domain = urlparse(self.url).netloc
|
||||
self.domain, _ = LinkDomain.objects.get_or_create(domain=domain)
|
||||
|
||||
# this is never broadcast, the owning model broadcasts an update
|
||||
if "broadcast" in kwargs:
|
||||
del kwargs["broadcast"]
|
||||
@ -43,7 +58,7 @@ StatusChoices = [
|
||||
class LinkDomain(BookWyrmModel):
|
||||
"""List of domains used in links"""
|
||||
|
||||
domain = models.CharField(max_length=255)
|
||||
domain = models.CharField(max_length=255, unique=True)
|
||||
status = models.CharField(max_length=50, choices=StatusChoices, default="pending")
|
||||
name = models.CharField(max_length=100)
|
||||
|
||||
|
Reference in New Issue
Block a user