1
0
mirror of https://gitlab.crans.org/mediatek/med.git synced 2024-11-27 10:53:10 +00:00

Fix borrowable autocompletion

This commit is contained in:
Yohann D'ANELLO 2021-10-26 15:07:37 +02:00
parent 1e6e033cdd
commit ae0d1a080e
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85

View File

@ -44,7 +44,17 @@ class Borrowable(PolymorphicModel):
)
def __str__(self):
return self.title
obj = self
if obj.__class__ == Borrowable:
# Get true object instance, useful for autocompletion
obj = Borrowable.objects.get(pk=obj.pk)
title = obj.title
if hasattr(obj, 'subtitle'):
subtitle = obj.subtitle
if subtitle:
title = f"{title} : {subtitle}"
return title
class Meta:
verbose_name = _('borrowable')
@ -99,12 +109,6 @@ class Book(Medium):
null=True,
)
def __str__(self):
if self.subtitle:
return "{} : {}".format(self.title, self.subtitle)
else:
return self.title
class Meta:
verbose_name = _("book")
verbose_name_plural = _("books")