Makes attachment Images a serializable class

This commit is contained in:
Mouse Reeve 2020-11-27 17:20:01 -08:00
parent 69a6644011
commit 624ff71a11
4 changed files with 56 additions and 13 deletions

View file

@ -0,0 +1,17 @@
# Generated by Django 3.0.7 on 2020-11-28 01:18
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('bookwyrm', '0013_book_origin_id'),
]
operations = [
migrations.RenameModel(
old_name='Attachment',
new_name='Image',
),
]

View file

@ -5,15 +5,21 @@ import sys
from .book import Book, Work, Edition
from .author import Author
from .connector import Connector
from .relationship import UserFollows, UserFollowRequest, UserBlocks
from .shelf import Shelf, ShelfBook
from .status import Status, GeneratedNote, Review, Comment, Quotation
from .status import Attachment, Favorite, Boost, Notification, ReadThrough
from .status import Favorite, Boost, Notification, ReadThrough
from .attachment import Image
from .tag import Tag
from .user import User
from .relationship import UserFollows, UserFollowRequest, UserBlocks
from .federated_server import FederatedServer
from .import_job import ImportJob, ImportItem
from .site import SiteSettings, SiteInvite, PasswordReset
cls_members = inspect.getmembers(sys.modules[__name__], inspect.isclass)

View file

@ -0,0 +1,31 @@
''' media that is posted in the app '''
from django.db import models
from bookwyrm import activitypub
from .base_model import ActivitypubMixin
from .base_model import ActivityMapping, BookWyrmModel
class Attachment(ActivitypubMixin, BookWyrmModel):
''' an image (or, in the future, video etc) associated with a status '''
status = models.ForeignKey(
'Status',
on_delete=models.CASCADE,
related_name='attachments'
)
class Meta:
''' one day we'll have other types of attachments besides images '''
abstract = True
activity_mappings = [
ActivityMapping('id', 'remote_id'),
ActivityMapping('url', 'image'),
ActivityMapping('name', 'caption'),
]
class Image(Attachment):
''' an image attachment '''
image = models.ImageField(upload_to='status/', null=True, blank=True)
caption = models.TextField(null=True, blank=True)
activity_serializer = activitypub.Image

View file

@ -151,17 +151,6 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel):
return super().save(*args, **kwargs)
class Attachment(BookWyrmModel):
''' an image (or, in the future, video etc) associated with a status '''
status = models.ForeignKey(
'Status',
on_delete=models.CASCADE,
related_name='attachments'
)
image = models.ImageField(upload_to='status/', null=True, blank=True)
caption = models.TextField(null=True, blank=True)
class GeneratedNote(Status):
''' these are app-generated messages about user activity '''
@property