1
0
Fork 0

Migrate default edition field to work model

Fixes #281
This commit is contained in:
Mouse Reeve 2020-11-04 10:35:13 -08:00
parent be4f41335e
commit ff96835c2a
5 changed files with 43 additions and 15 deletions

View file

@ -128,9 +128,10 @@ class AbstractConnector(ABC):
if not edition:
ed_key = self.get_remote_id_from_data(edition_data)
edition = self.create_book(ed_key, edition_data, models.Edition)
edition.default = True
edition.parent_work = work
edition.save()
work.default_edition = edition
work.save()
# now's our change to fill in author gaps
if not edition.authors and work.authors:

View file

@ -72,7 +72,6 @@ class Connector(AbstractConnector):
]
def get_remote_id_from_data(self, data):
try:
key = data['key']

View file

@ -1,5 +1,6 @@
''' using a bookwyrm instance as a source of book data '''
from django.contrib.postgres.search import SearchRank, SearchVector
from django.db.models import F
from bookwyrm import models
from .abstract_connector import AbstractConnector, SearchResult
@ -30,7 +31,10 @@ class Connector(AbstractConnector):
).filter(
rank__gt=min_confidence
).order_by('-rank')
results = results.filter(default=True) or results
# remove non-default editions, if possible
results = results.filter(parent_work__default_edition__id=F('id')) \
or results
search_results = []
for book in results[:10]: