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