forked from mirrors/bookwyrm
Makes attachment Images a serializable class
This commit is contained in:
parent
69a6644011
commit
624ff71a11
4 changed files with 56 additions and 13 deletions
17
bookwyrm/migrations/0014_auto_20201128_0118.py
Normal file
17
bookwyrm/migrations/0014_auto_20201128_0118.py
Normal 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',
|
||||||
|
),
|
||||||
|
]
|
|
@ -5,15 +5,21 @@ import sys
|
||||||
from .book import Book, Work, Edition
|
from .book import Book, Work, Edition
|
||||||
from .author import Author
|
from .author import Author
|
||||||
from .connector import Connector
|
from .connector import Connector
|
||||||
from .relationship import UserFollows, UserFollowRequest, UserBlocks
|
|
||||||
from .shelf import Shelf, ShelfBook
|
from .shelf import Shelf, ShelfBook
|
||||||
|
|
||||||
from .status import Status, GeneratedNote, Review, Comment, Quotation
|
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 .tag import Tag
|
||||||
|
|
||||||
from .user import User
|
from .user import User
|
||||||
|
from .relationship import UserFollows, UserFollowRequest, UserBlocks
|
||||||
from .federated_server import FederatedServer
|
from .federated_server import FederatedServer
|
||||||
|
|
||||||
from .import_job import ImportJob, ImportItem
|
from .import_job import ImportJob, ImportItem
|
||||||
|
|
||||||
from .site import SiteSettings, SiteInvite, PasswordReset
|
from .site import SiteSettings, SiteInvite, PasswordReset
|
||||||
|
|
||||||
cls_members = inspect.getmembers(sys.modules[__name__], inspect.isclass)
|
cls_members = inspect.getmembers(sys.modules[__name__], inspect.isclass)
|
||||||
|
|
31
bookwyrm/models/attachment.py
Normal file
31
bookwyrm/models/attachment.py
Normal 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
|
|
@ -151,17 +151,6 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel):
|
||||||
return super().save(*args, **kwargs)
|
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):
|
class GeneratedNote(Status):
|
||||||
''' these are app-generated messages about user activity '''
|
''' these are app-generated messages about user activity '''
|
||||||
@property
|
@property
|
||||||
|
|
Loading…
Reference in a new issue