2018-01-16 08:32:06 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
|
|
|
|
from django.db import models
|
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
|
2022-12-07 10:58:57 +00:00
|
|
|
from common.utils import lazyproperty
|
2022-10-10 05:56:42 +00:00
|
|
|
from orgs.mixins.models import JMSOrgBaseModel
|
2018-01-16 08:32:06 +00:00
|
|
|
|
2022-10-10 05:56:42 +00:00
|
|
|
|
|
|
|
class Label(JMSOrgBaseModel):
|
2018-01-16 08:32:06 +00:00
|
|
|
SYSTEM_CATEGORY = "S"
|
|
|
|
USER_CATEGORY = "U"
|
|
|
|
CATEGORY_CHOICES = (
|
|
|
|
("S", _("System")),
|
|
|
|
("U", _("User"))
|
|
|
|
)
|
|
|
|
name = models.CharField(max_length=128, verbose_name=_("Name"))
|
|
|
|
value = models.CharField(max_length=128, verbose_name=_("Value"))
|
2018-12-10 05:03:02 +00:00
|
|
|
category = models.CharField(max_length=128, choices=CATEGORY_CHOICES,
|
|
|
|
default=USER_CATEGORY, verbose_name=_("Category"))
|
2018-01-16 08:32:06 +00:00
|
|
|
is_active = models.BooleanField(default=True, verbose_name=_("Is active"))
|
|
|
|
|
2018-01-23 11:37:22 +00:00
|
|
|
@classmethod
|
|
|
|
def get_queryset_group_by_name(cls):
|
|
|
|
names = cls.objects.values_list('name', flat=True)
|
|
|
|
for name in names:
|
|
|
|
yield name, cls.objects.filter(name=name)
|
|
|
|
|
2022-12-07 10:58:57 +00:00
|
|
|
@lazyproperty
|
|
|
|
def asset_count(self):
|
|
|
|
return self.assets.count()
|
|
|
|
|
2018-01-16 08:32:06 +00:00
|
|
|
def __str__(self):
|
|
|
|
return "{}:{}".format(self.name, self.value)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
db_table = "assets_label"
|
2018-08-16 04:44:39 +00:00
|
|
|
unique_together = [('name', 'value', 'org_id')]
|
2022-02-17 12:13:31 +00:00
|
|
|
verbose_name = _('Label')
|