bookwyrm-mastodon/bookwyrm/models/link.py

34 lines
949 B
Python
Raw Normal View History

2021-10-04 16:14:32 -04:00
""" outlink data """
2021-12-15 19:23:21 -05:00
from django.db import models
from bookwyrm import activitypub
2021-12-15 15:40:31 -05:00
from .activitypub_mixin import ActivitypubMixin
2021-10-04 16:14:32 -04:00
from .base_model import BookWyrmModel
from . import fields
2021-10-07 19:53:39 -04:00
2021-12-15 15:40:31 -05:00
class Link(ActivitypubMixin, BookWyrmModel):
2021-10-04 16:14:32 -04:00
"""a link to a website"""
2021-12-15 19:23:21 -05:00
url = fields.URLField(max_length=255, activitypub_field="href")
2021-10-04 16:14:32 -04:00
name = fields.CharField(max_length=255)
2021-12-15 19:23:21 -05:00
activity_serializer = activitypub.Link
reverse_unfurl = True
2021-12-15 15:40:31 -05:00
def save(self, *args, **kwargs):
"""create a link"""
# this is never broadcast, the owning model broadcasts an update
if "broadcast" in kwargs:
del kwargs["broadcast"]
return super().save(*args, **kwargs)
2021-10-04 16:14:32 -04:00
class FileLink(Link):
"""a link to a file"""
2021-12-15 19:23:21 -05:00
book = fields.ForeignKey(
"Book", on_delete=models.CASCADE, related_name="file_links", null=True
)
filetype = fields.CharField(max_length=5, activitypub_field="mediaType")