Fix editor retrieval when multiple editors are returned

This commit is contained in:
Gabriel Augendre 2020-06-30 13:14:47 +02:00
parent 0bdbe79828
commit df8ef43b58
No known key found for this signature in database
GPG key ID: 1E693F4CE4AEE7B4

View file

@ -285,12 +285,15 @@ class Book(BaseModel):
self.authors = decitre_data.get('authors')
self.price = decitre_data.get('price')
self.publication_year = decitre_data.get('year')
editor = decitre_data.get('editor')
try:
self.editor = Editor.objects.get(name__icontains=editor)
except Editor.DoesNotExist:
self.editor = Editor.objects.get(name__istartswith='autre')
editor = decitre_data.get('editor')
potential_editor = (
Editor.objects.filter(name__iexact=editor).first()
or Editor.objects.filter(name__icontains=editor).first()
or Editor.objects.get(name__istartswith="autre")
)
self.editor = potential_editor
self.save()
@property