2020-11-27 20:20:01 -05:00
|
|
|
''' media that is posted in the app '''
|
|
|
|
from django.db import models
|
|
|
|
|
|
|
|
from bookwyrm import activitypub
|
2021-02-04 13:47:03 -05:00
|
|
|
from .activitypub_mixin import ActivitypubMixin
|
2020-11-30 17:24:31 -05:00
|
|
|
from .base_model import BookWyrmModel
|
|
|
|
from . import fields
|
2020-11-27 20:20:01 -05:00
|
|
|
|
|
|
|
|
|
|
|
class Attachment(ActivitypubMixin, BookWyrmModel):
|
|
|
|
''' an image (or, in the future, video etc) associated with a status '''
|
2020-12-07 21:28:42 -05:00
|
|
|
status = models.ForeignKey(
|
2020-11-27 20:20:01 -05:00
|
|
|
'Status',
|
|
|
|
on_delete=models.CASCADE,
|
2020-11-27 23:11:22 -05:00
|
|
|
related_name='attachments',
|
|
|
|
null=True
|
2020-11-27 20:20:01 -05:00
|
|
|
)
|
2020-11-30 17:24:31 -05:00
|
|
|
reverse_unfurl = True
|
2020-11-27 20:20:01 -05:00
|
|
|
class Meta:
|
|
|
|
''' one day we'll have other types of attachments besides images '''
|
|
|
|
abstract = True
|
|
|
|
|
|
|
|
|
|
|
|
class Image(Attachment):
|
|
|
|
''' an image attachment '''
|
2020-12-07 21:28:42 -05:00
|
|
|
image = fields.ImageField(
|
|
|
|
upload_to='status/', null=True, blank=True, activitypub_field='url')
|
|
|
|
caption = fields.TextField(null=True, blank=True, activitypub_field='name')
|
2020-11-27 20:20:01 -05:00
|
|
|
|
|
|
|
activity_serializer = activitypub.Image
|