mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 19:41:11 +00:00
lookup books when resolving activity json
This commit is contained in:
parent
02265b1e49
commit
9ef03664f2
1 changed files with 5 additions and 0 deletions
|
@ -2,6 +2,8 @@
|
||||||
from dataclasses import dataclass, fields, MISSING
|
from dataclasses import dataclass, fields, MISSING
|
||||||
from json import JSONEncoder
|
from json import JSONEncoder
|
||||||
|
|
||||||
|
from bookwyrm import books_manager, models
|
||||||
|
|
||||||
from django.db.models.fields.related_descriptors \
|
from django.db.models.fields.related_descriptors \
|
||||||
import ForwardManyToOneDescriptor
|
import ForwardManyToOneDescriptor
|
||||||
|
|
||||||
|
@ -102,6 +104,9 @@ class ActivityObject:
|
||||||
|
|
||||||
def resolve_foreign_key(model, remote_id):
|
def resolve_foreign_key(model, remote_id):
|
||||||
''' look up the remote_id on an activity json field '''
|
''' look up the remote_id on an activity json field '''
|
||||||
|
if model in [models.Edition, models.Work]:
|
||||||
|
return books_manager.get_or_create_book(remote_id)
|
||||||
|
|
||||||
result = model.objects
|
result = model.objects
|
||||||
if hasattr(model.objects, 'select_subclasses'):
|
if hasattr(model.objects, 'select_subclasses'):
|
||||||
result = result.select_subclasses()
|
result = result.select_subclasses()
|
||||||
|
|
Loading…
Reference in a new issue