moviewyrm/bookwyrm/models/attachment.py

37 lines
961 B
Python
Raw Permalink Normal View History

2021-03-08 16:49:10 +00:00
""" media that is posted in the app """
from django.db import models
from bookwyrm import activitypub
from .activitypub_mixin import ActivitypubMixin
2020-11-30 22:24:31 +00:00
from .base_model import BookWyrmModel
from . import fields
class Attachment(ActivitypubMixin, BookWyrmModel):
2021-03-08 16:49:10 +00:00
""" an image (or, in the future, video etc) associated with a status """
status = models.ForeignKey(
2021-03-08 16:49:10 +00:00
"Status", on_delete=models.CASCADE, related_name="attachments", null=True
)
2020-11-30 22:24:31 +00:00
reverse_unfurl = True
2021-03-08 16:49:10 +00:00
class Meta:
2021-03-08 16:49:10 +00:00
""" one day we'll have other types of attachments besides images """
abstract = True
class Image(Attachment):
2021-03-08 16:49:10 +00:00
""" an image attachment """
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")
2021-04-15 23:35:04 +00:00
activity_serializer = activitypub.Document