Export decitre URL in export
This commit is contained in:
parent
f4c92e9c65
commit
83e35ddb9c
2 changed files with 11 additions and 2 deletions
|
@ -101,14 +101,16 @@ class LevelAdmin(ExportMixin, admin.ModelAdmin):
|
||||||
|
|
||||||
|
|
||||||
class BookResource(resources.ModelResource):
|
class BookResource(resources.ModelResource):
|
||||||
|
decitre_url = fields.Field(attribute='decitre_url')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Book
|
model = Book
|
||||||
fields = ('title', 'authors', 'editor__name', 'publication_year', 'isbn', 'comments', 'other_editor',
|
fields = ('title', 'authors', 'editor__name', 'publication_year', 'isbn', 'comments', 'other_editor',
|
||||||
'price', 'previously_acquired', 'teacher__first_name', 'teacher__last_name', 'level__name', 'field',
|
'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',
|
export_order = ('level__name', 'field', 'title', 'authors', 'editor__name', 'publication_year', 'isbn', 'price',
|
||||||
'other_editor', 'previously_acquired', 'teacher__first_name', 'teacher__last_name', 'comments',
|
'other_editor', 'previously_acquired', 'teacher__first_name', 'teacher__last_name', 'comments',
|
||||||
'consumable')
|
'consumable', "decitre_url")
|
||||||
|
|
||||||
|
|
||||||
@admin.register(Book)
|
@admin.register(Book)
|
||||||
|
|
|
@ -293,6 +293,13 @@ class Book(BaseModel):
|
||||||
|
|
||||||
self.save()
|
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
|
@staticmethod
|
||||||
def fetch_from_decitre(isbn: str):
|
def fetch_from_decitre(isbn: str):
|
||||||
isbn = isbn.strip().replace('-', '')
|
isbn = isbn.strip().replace('-', '')
|
||||||
|
|
Loading…
Reference in a new issue