simplify subtitle logic

This commit is contained in:
Laura Klünder 2017-10-27 14:51:26 +02:00
parent 58f1ae9ee3
commit 508a45b4c8

View file

@ -157,14 +157,9 @@ class SpecificLocation(Location, models.Model):
@property
def subtitle(self):
related_name = self.__class__._meta.default_related_name
groups = tuple(self.groups.all())
if groups:
group = max((group for group in groups if getattr(group.category, 'allow_'+related_name)),
key=lambda group: (group.category.priority, group.priority), default=None)
return group.title
else:
return str(self.__class__._meta.verbose_name)
return groups[0].title if groups else str(self.__class__._meta.verbose_name)
class LocationGroupCategory(TitledMixin, models.Model):