Re-structures link models

This commit is contained in:
Mouse Reeve
2021-12-15 16:23:21 -08:00
parent af8cb51325
commit 86b294afd7
7 changed files with 32 additions and 27 deletions

View File

@ -44,7 +44,6 @@ class BookDataModel(ObjectMixin, BookWyrmModel):
bnf_id = fields.CharField( # Bibliothèque nationale de France
max_length=255, blank=True, null=True, deduplication_field=True
)
links = fields.ManyToManyField("Link")
search_vector = SearchVectorField(null=True)
last_edited_by = fields.ForeignKey(
@ -116,7 +115,6 @@ class Book(BookDataModel):
objects = InheritanceManager()
field_tracker = FieldTracker(fields=["authors", "title", "subtitle", "cover"])
file_links = fields.ManyToManyField("FileLink", related_name="editions")
if ENABLE_THUMBNAIL_GENERATION:
cover_bw_book_xsmall_webp = ImageSpecField(
@ -237,7 +235,7 @@ class Work(OrderedCollectionPageMixin, Book):
activity_serializer = activitypub.Work
serialize_reverse_fields = [("editions", "editions", "-edition_rank")]
deserialize_reverse_fields = [("editions", "editions")]
deserialize_reverse_fields = [("editions", "editions"), ("file_links", "fileLinks")]
# https://schema.org/BookFormatType

View File

@ -1,4 +1,7 @@
""" outlink data """
from django.db import models
from bookwyrm import activitypub
from .activitypub_mixin import ActivitypubMixin
from .base_model import BookWyrmModel
from . import fields
@ -7,9 +10,12 @@ from . import fields
class Link(ActivitypubMixin, BookWyrmModel):
"""a link to a website"""
url = fields.URLField(max_length=255)
url = fields.URLField(max_length=255, activitypub_field="href")
name = fields.CharField(max_length=255)
activity_serializer = activitypub.Link
reverse_unfurl = True
def save(self, *args, **kwargs):
"""create a link"""
# this is never broadcast, the owning model broadcasts an update
@ -21,4 +27,7 @@ class Link(ActivitypubMixin, BookWyrmModel):
class FileLink(Link):
"""a link to a file"""
filetype = fields.CharField(max_length=5)
book = fields.ForeignKey(
"Book", on_delete=models.CASCADE, related_name="file_links", null=True
)
filetype = fields.CharField(max_length=5, activitypub_field="mediaType")