summaryrefslogtreecommitdiff
path: root/app/taxonomy
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2019-04-11 19:46:12 -0500
committerluxagraf <sng@luxagraf.net>2019-04-11 19:46:12 -0500
commit86fcf7ed710f41fc5324b638d092af54f4bb756f (patch)
tree28634fddbddb5ac162cd142c8e3a668d2296e414 /app/taxonomy
initial commit
Diffstat (limited to 'app/taxonomy')
-rw-r--r--app/taxonomy/migrations/0001_initial.py52
-rw-r--r--app/taxonomy/migrations/__init__.py0
-rw-r--r--app/taxonomy/models.py39
3 files changed, 91 insertions, 0 deletions
diff --git a/app/taxonomy/migrations/0001_initial.py b/app/taxonomy/migrations/0001_initial.py
new file mode 100644
index 0000000..a181161
--- /dev/null
+++ b/app/taxonomy/migrations/0001_initial.py
@@ -0,0 +1,52 @@
+# Generated by Django 2.1.7 on 2019-03-30 17:07
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ initial = True
+
+ dependencies = [
+ ('contenttypes', '0002_remove_content_type_name'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='Category',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('name', models.CharField(max_length=250)),
+ ('color_rgb', models.CharField(blank=True, max_length=20)),
+ ('slug', models.SlugField(blank=True)),
+ ('date_created', models.DateTimeField(auto_now_add=True)),
+ ('date_updated', models.DateTimeField(auto_now=True)),
+ ],
+ ),
+ migrations.CreateModel(
+ name='LuxTag',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('name', models.CharField(max_length=100, unique=True, verbose_name='Name')),
+ ('slug', models.SlugField(max_length=100, unique=True, verbose_name='Slug')),
+ ('color_rgb', models.CharField(blank=True, max_length=20)),
+ ],
+ options={
+ 'verbose_name_plural': 'Tags',
+ 'verbose_name': 'Tag',
+ },
+ ),
+ migrations.CreateModel(
+ name='TaggedItems',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('object_id', models.IntegerField(db_index=True, verbose_name='Object id')),
+ ('content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='taxonomy_taggeditems_tagged_items', to='contenttypes.ContentType', verbose_name='Content type')),
+ ('tag', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='taxonomy_taggeditems_items', to='taxonomy.LuxTag')),
+ ],
+ options={
+ 'abstract': False,
+ },
+ ),
+ ]
diff --git a/app/taxonomy/migrations/__init__.py b/app/taxonomy/migrations/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/app/taxonomy/migrations/__init__.py
diff --git a/app/taxonomy/models.py b/app/taxonomy/models.py
new file mode 100644
index 0000000..df38ae7
--- /dev/null
+++ b/app/taxonomy/models.py
@@ -0,0 +1,39 @@
+from django.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:tags", 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)
+ color_rgb = models.CharField(max_length=20, blank=True)
+ slug = models.SlugField(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
+
+ def get_absolute_url(self):
+ return reverse("taxonomy:categories", kwargs={"slug": self.slug})