From df8ef43b581cde797d68ec15d0769a6dba2271ea Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Tue, 30 Jun 2020 13:14:47 +0200 Subject: [PATCH] Fix editor retrieval when multiple editors are returned --- manuels/models.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/manuels/models.py b/manuels/models.py index 4030cc1..841bf67 100644 --- a/manuels/models.py +++ b/manuels/models.py @@ -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