Use media str method for admin

This commit is contained in:
Alexandre Iooss 2019-08-15 11:37:10 +02:00
parent 04c00fd5d0
commit 626990b119
No known key found for this signature in database
GPG Key ID: 6C79278F3FCDCC02
2 changed files with 5 additions and 11 deletions

View File

@ -18,7 +18,7 @@ class AuteurAdmin(VersionAdmin):
class MediaAdmin(VersionAdmin): class MediaAdmin(VersionAdmin):
list_display = ('full_name', 'authors_list', 'side_identifier', 'isbn', list_display = ('__str__', 'authors_list', 'side_identifier', 'isbn',
'external_link') 'external_link')
search_fields = ('title', 'authors__nom', 'side_identifier', 'subtitle', search_fields = ('title', 'authors__nom', 'side_identifier', 'subtitle',
'isbn') 'isbn')
@ -26,14 +26,6 @@ class MediaAdmin(VersionAdmin):
date_hierarchy = 'publish_date' date_hierarchy = 'publish_date'
form = MediaAdminForm form = MediaAdminForm
def full_name(self, obj):
if obj.subtitle:
return "{} : {}".format(obj.title, obj.subtitle)
else:
return obj.title
full_name.short_description = _('name')
def authors_list(self, obj): def authors_list(self, obj):
return ", ".join([a.nom for a in obj.authors.all()]) return ", ".join([a.nom for a in obj.authors.all()])

View File

@ -63,8 +63,10 @@ class Media(models.Model):
) )
def __str__(self): def __str__(self):
return str(self.title) + ' - ' + str(self.subtitle) \ if self.subtitle:
+ ' - ' + str(self.authors.all().first()) return "{} : {}".format(self.title, self.subtitle)
else:
return self.title
class Meta: class Meta:
verbose_name = _("medium") verbose_name = _("medium")