Starts getting reverse fields working for deserialization
also fixes the fields on the image model and runs a long overdue migration
This commit is contained in:
parent
d0c1a68df6
commit
4d4ee8b8c3
8 changed files with 434 additions and 59 deletions
|
@ -9,7 +9,7 @@ from . import fields
|
|||
|
||||
class Attachment(ActivitypubMixin, BookWyrmModel):
|
||||
''' an image (or, in the future, video etc) associated with a status '''
|
||||
status = fields.ForeignKey(
|
||||
status = models.ForeignKey(
|
||||
'Status',
|
||||
on_delete=models.CASCADE,
|
||||
related_name='attachments',
|
||||
|
@ -23,7 +23,8 @@ class Attachment(ActivitypubMixin, BookWyrmModel):
|
|||
|
||||
class Image(Attachment):
|
||||
''' an image attachment '''
|
||||
image = fields.ImageField(upload_to='status/', null=True, blank=True)
|
||||
caption = fields.TextField(null=True, blank=True)
|
||||
image = fields.ImageField(
|
||||
upload_to='status/', null=True, blank=True, activitypub_field='url')
|
||||
caption = fields.TextField(null=True, blank=True, activitypub_field='name')
|
||||
|
||||
activity_serializer = activitypub.Image
|
||||
|
|
|
@ -83,9 +83,11 @@ class ActivitypubMixin:
|
|||
|
||||
if hasattr(self, 'serialize_reverse_fields'):
|
||||
# for example, editions of a work
|
||||
for field_name in self.serialize_reverse_fields:
|
||||
related_field = getattr(self, field_name)
|
||||
activity[field_name] = unfurl_related_field(related_field)
|
||||
for model_field_name, activity_field_name in \
|
||||
self.serialize_reverse_fields:
|
||||
related_field = getattr(self, model_field_name)
|
||||
activity[activity_field_name] = \
|
||||
unfurl_related_field(related_field)
|
||||
|
||||
if not activity.get('id'):
|
||||
activity['id'] = self.get_remote_id()
|
||||
|
|
|
@ -96,7 +96,8 @@ class Work(OrderedCollectionPageMixin, Book):
|
|||
return self.default_edition or self.editions.first()
|
||||
|
||||
activity_serializer = activitypub.Work
|
||||
serialize_reverse_fields = ['editions']
|
||||
serialize_reverse_fields = [('editions', 'editions')]
|
||||
deserialize_reverse_fields = [('editions', 'editions')]
|
||||
|
||||
|
||||
class Edition(Book):
|
||||
|
|
|
@ -45,7 +45,8 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel):
|
|||
objects = InheritanceManager()
|
||||
|
||||
activity_serializer = activitypub.Note
|
||||
serialize_reverse_fields = ['attachments']
|
||||
serialize_reverse_fields = [('attachments', 'attachment')]
|
||||
deserialize_reverse_fields = [('attachments', 'attachment')]
|
||||
|
||||
#----- replies collection activitypub ----#
|
||||
@classmethod
|
||||
|
|
|
@ -166,7 +166,7 @@ class KeyPair(ActivitypubMixin, BookWyrmModel):
|
|||
blank=True, null=True, activitypub_field='publicKeyPem')
|
||||
|
||||
activity_serializer = activitypub.PublicKey
|
||||
serialize_reverse_fields = ['owner']
|
||||
serialize_reverse_fields = [('owner', 'owner')]
|
||||
|
||||
def get_remote_id(self):
|
||||
# self.owner is set by the OneToOneField on User
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue