gault-millau/apps/tag/models.py
2019-10-08 15:38:35 +03:00

52 lines
1.7 KiB
Python

"""Tag app models."""
from django.db import models
from django.utils.translation import gettext_lazy as _
from configuration.models import TranslationSettings
from utils.models import TJSONField, TranslatedFieldsMixin
class Tag(TranslatedFieldsMixin, models.Model):
"""Tag model."""
label = TJSONField(
_('label'), null=True, blank=True,
default=None, help_text='{"en-GB":"some text"}')
category = models.ForeignKey('TagCategory',
on_delete=models.SET_NULL, null=True,
related_name='tags',
verbose_name='category')
class Meta:
verbose_name = _('tag')
verbose_name_plural = _('tags')
def __str__(self):
label = 'None'
lang = TranslationSettings.get_solo().default_language
if self.label and lang in self.label:
label = self.label[lang]
return f'id:{self.id}-{label}'
class TagCategory(TranslatedFieldsMixin, models.Model):
"""Tag base category model."""
label = TJSONField(
_('label'), null=True, blank=True,
default=None, help_text='{"en-GB":"some text"}')
country = models.ForeignKey('location.Country',
on_delete=models.SET_NULL, null=True,
default=None)
public = models.BooleanField(default=False)
class Meta:
verbose_name = _('tag category')
verbose_name_plural = _('tag categories')
def __str__(self):
label = 'None'
lang = TranslationSettings.get_solo().default_language
if self.label and lang in self.label:
label = self.label[lang]
return f'id:{self.id}-{label}'