diff --git a/manuels/admin.py b/manuels/admin.py index c3051ce..238c231 100644 --- a/manuels/admin.py +++ b/manuels/admin.py @@ -101,14 +101,16 @@ class LevelAdmin(ExportMixin, admin.ModelAdmin): class BookResource(resources.ModelResource): + decitre_url = fields.Field(attribute='decitre_url') + class Meta: model = Book fields = ('title', 'authors', 'editor__name', 'publication_year', 'isbn', 'comments', 'other_editor', 'price', 'previously_acquired', 'teacher__first_name', 'teacher__last_name', 'level__name', 'field', - 'consumable') + 'consumable', "decitre_url") export_order = ('level__name', 'field', 'title', 'authors', 'editor__name', 'publication_year', 'isbn', 'price', 'other_editor', 'previously_acquired', 'teacher__first_name', 'teacher__last_name', 'comments', - 'consumable') + 'consumable', "decitre_url") @admin.register(Book) diff --git a/manuels/models.py b/manuels/models.py index c12b5b2..4030cc1 100644 --- a/manuels/models.py +++ b/manuels/models.py @@ -293,6 +293,13 @@ class Book(BaseModel): self.save() + @property + def decitre_url(self): + isbn = self.isbn.strip().replace('-', '') + if not validate_isbn(isbn) or len(isbn) == 10: + return "" + return f'https://www.decitre.fr/livres/{isbn}.html' + @staticmethod def fetch_from_decitre(isbn: str): isbn = isbn.strip().replace('-', '')