add first subtitle code
This commit is contained in:
parent
ebca3361d3
commit
25b478f227
2 changed files with 41 additions and 20 deletions
|
@ -81,6 +81,7 @@ class Location(LocationSlug, AccessRestrictionMixin, TitledMixin, models.Model):
|
|||
|
||||
def _serialize(self, **kwargs):
|
||||
result = super()._serialize(**kwargs)
|
||||
result['subtitle'] = self.subtitle
|
||||
result['can_search'] = self.can_search
|
||||
result['can_describe'] = self.can_search
|
||||
return result
|
||||
|
@ -122,6 +123,10 @@ class Location(LocationSlug, AccessRestrictionMixin, TitledMixin, models.Model):
|
|||
return self._meta.verbose_name + ' ' + self.slug
|
||||
return super().title
|
||||
|
||||
@property
|
||||
def subtitle(self):
|
||||
return ''
|
||||
|
||||
def get_color(self, instance=None):
|
||||
# dont filter in the query here so prefetch_related works
|
||||
if instance is None:
|
||||
|
@ -150,6 +155,17 @@ class SpecificLocation(Location, models.Model):
|
|||
result['groups'] = groups
|
||||
return result
|
||||
|
||||
@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)
|
||||
|
||||
|
||||
class LocationGroupCategory(TitledMixin, models.Model):
|
||||
name = models.SlugField(_('Name'), unique=True, max_length=50)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue