diff options
Diffstat (limited to 'app/taxonomy/models.py')
-rw-r--r-- | app/taxonomy/models.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/app/taxonomy/models.py b/app/taxonomy/models.py new file mode 100644 index 0000000..4db3294 --- /dev/null +++ b/app/taxonomy/models.py @@ -0,0 +1,44 @@ +from django.contrib.gis.db import models +from django.urls import reverse +from django.utils.translation import ugettext_lazy as _ +from django.utils.functional import cached_property + +from taggit.models import TagBase, GenericTaggedItemBase + + +class LuxTag(TagBase): + ''' override the default taggit model to add some color ''' + color_rgb = models.CharField(max_length=20, blank=True) + + class Meta: + verbose_name = _("Tag") + verbose_name_plural = _("Tags") + + @cached_property + def get_absolute_url(self): + return reverse("taxonomy:cat-detail", kwargs={"slug": self.slug}) + + +class TaggedItems(GenericTaggedItemBase): + ''' necessary with custom tag model, lets you still use TaggableManager''' + tag = models.ForeignKey(LuxTag, related_name="%(app_label)s_%(class)s_items", on_delete=models.CASCADE) + + +class Category(models.Model): + """ Generic model for Categories """ + name = models.CharField(max_length=250) + pluralized_name = models.CharField(max_length=60, null=True) + slug = models.SlugField(blank=True) + color_rgb = models.CharField(max_length=20, blank=True) + date_created = models.DateTimeField(blank=True, auto_now_add=True, editable=False) + date_updated = models.DateTimeField(blank=True, auto_now=True, editable=False) + + def __str__(self): + return self.name + + class Meta: + verbose_name = _("Category") + verbose_name_plural = _("Categories") + + def get_absolute_url(self): + return reverse("taxonomy:cat-detail", kwargs={"slug": self.slug}) |