diff --git a/bookwyrm/activitypub/book.py b/bookwyrm/activitypub/book.py index ae9c334d..93cd384f 100644 --- a/bookwyrm/activitypub/book.py +++ b/bookwyrm/activitypub/book.py @@ -38,7 +38,7 @@ class Edition(Book): isbn13: str = '' oclcNumber: str = '' asin: str = '' - pages: str = '' + pages: int = None physicalFormat: str = '' publishers: List[str] = field(default_factory=lambda: []) diff --git a/bookwyrm/models/book.py b/bookwyrm/models/book.py index 3080a115..8d441e8b 100644 --- a/bookwyrm/models/book.py +++ b/bookwyrm/models/book.py @@ -92,7 +92,8 @@ class Work(OrderedCollectionPageMixin, Book): default_edition = fields.ForeignKey( 'Edition', on_delete=models.PROTECT, - null=True + null=True, + load_remote=False ) def get_default_edition(self): diff --git a/bookwyrm/models/fields.py b/bookwyrm/models/fields.py index 52933715..082ac53b 100644 --- a/bookwyrm/models/fields.py +++ b/bookwyrm/models/fields.py @@ -100,12 +100,19 @@ class ActivitypubFieldMixin: class ActivitypubRelatedFieldMixin(ActivitypubFieldMixin): ''' default (de)serialization for foreign key and one to one ''' + def __init__(self, *args, load_remote=True, **kwargs): + self.load_remote = load_remote + super().__init__(*args, **kwargs) + def field_from_activity(self, value): if not value: return None related_model = self.related_model if isinstance(value, dict) and value.get('id'): + if not self.load_remote: + # only look in the local database + return related_model.find_existing(value) # this is an activitypub object, which we can deserialize activity_serializer = related_model.activity_serializer return activity_serializer(**value).to_model(related_model) @@ -116,6 +123,9 @@ class ActivitypubRelatedFieldMixin(ActivitypubFieldMixin): # we don't know what this is, ignore it return None # gets or creates the model field from the remote id + if not self.load_remote: + # only look in the local database + return related_model.find_existing_by_remote_id(value) return activitypub.resolve_remote_id(related_model, value)