Added the get_multi_language_attr() function to the Mia core application, to deal with the multi-lingual attributes, and applied it in the data models.

This commit is contained in:
2020-07-14 22:01:32 +08:00
parent a8d18ddd1e
commit fa034b9a6a
5 changed files with 92 additions and 11 deletions

View File

@ -21,6 +21,8 @@
from django.db import models
from mia_core.utils import get_multi_language_attr
class Country(models.Model):
"""A country."""
@ -46,6 +48,18 @@ class Country(models.Model):
"""Returns the string representation of this country."""
return self.code.__str__() + " " + self.name_zhtw.__str__()
_title = None
@property
def title(self):
if self._title is None:
self._title = get_multi_language_attr(self, "title")
return self._title
@title.setter
def title(self, value):
self._title = value
class Meta:
db_table = "countries"
ordering = ["code"]