move title property to Location
This commit is contained in:
parent
da69a8813a
commit
513bb25b6a
2 changed files with 10 additions and 11 deletions
|
@ -5,7 +5,7 @@ from django.core.cache import cache
|
|||
from django.db import models
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import ungettext_lazy
|
||||
from django.utils.translation import get_language, ungettext_lazy
|
||||
|
||||
from c3nav.mapdata.fields import GeometryField, JSONField, validate_bssid_lines
|
||||
from c3nav.mapdata.lastupdate import get_last_mapdata_update
|
||||
|
@ -42,6 +42,15 @@ class Location(LocationSlug, models.Model):
|
|||
result['titles'] = OrderedDict(sorted(self.titles.items()))
|
||||
return result
|
||||
|
||||
@property
|
||||
def title(self):
|
||||
if not hasattr(self, 'titles'):
|
||||
return self.name
|
||||
lang = get_language()
|
||||
if lang in self.titles:
|
||||
return self.titles[lang]
|
||||
return next(iter(self.titles.values())) if self.titles else self.name
|
||||
|
||||
@property
|
||||
def subtitle(self):
|
||||
return self._meta.verbose_name
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue