Export decitre URL in export

This commit is contained in:
Gabriel Augendre 2020-06-01 13:53:46 +02:00
parent f4c92e9c65
commit 83e35ddb9c
2 changed files with 11 additions and 2 deletions

View file

@ -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)

View file

@ -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('-', '')