summaryrefslogtreecommitdiff
path: root/app/taxonomy
diff options
context:
space:
mode:
Diffstat (limited to 'app/taxonomy')
-rw-r--r--app/taxonomy/admin.py54
-rw-r--r--app/taxonomy/migrations/0001_initial.py57
-rw-r--r--app/taxonomy/migrations/0002_auto_20211006_2025.py28
-rw-r--r--app/taxonomy/migrations/__init__.py0
-rw-r--r--app/taxonomy/models.py44
-rw-r--r--app/taxonomy/urls.py13
-rw-r--r--app/taxonomy/views.py14
7 files changed, 210 insertions, 0 deletions
diff --git a/app/taxonomy/admin.py b/app/taxonomy/admin.py
new file mode 100644
index 0000000..783584e
--- /dev/null
+++ b/app/taxonomy/admin.py
@@ -0,0 +1,54 @@
+from django.contrib import admin
+from .models import Category, LuxTag
+
+
+@admin.register(Category)
+class CategoryAdmin(admin.ModelAdmin):
+ list_display = (
+ 'name',
+ 'color_rgb',
+ )
+ fieldsets = (
+ ('Item', {
+ 'fields': (
+ 'name',
+ 'color_rgb',
+ 'slug',
+ ),
+ 'classes': (
+ 'show',
+ 'extrapretty',
+ 'wide'
+ )
+ }
+ ),
+ )
+
+ class Media:
+ js = ('image-loader.js', 'next-prev-links.js')
+
+
+@admin.register(LuxTag)
+class LuxTagAdmin(admin.ModelAdmin):
+ list_display = (
+ 'name',
+ 'color_rgb',
+ )
+ fieldsets = (
+ ('Item', {
+ 'fields': (
+ 'name',
+ 'color_rgb',
+ 'slug',
+ ),
+ 'classes': (
+ 'show',
+ 'extrapretty',
+ 'wide'
+ )
+ }
+ ),
+ )
+
+ class Media:
+ js = ('image-loader.js', 'next-prev-links.js')
diff --git a/app/taxonomy/migrations/0001_initial.py b/app/taxonomy/migrations/0001_initial.py
new file mode 100644
index 0000000..bde5e44
--- /dev/null
+++ b/app/taxonomy/migrations/0001_initial.py
@@ -0,0 +1,57 @@
+# Generated by Django 3.1.3 on 2020-11-30 22:45
+
+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)),
+ ('pluralized_name', models.CharField(max_length=60, null=True)),
+ ('slug', models.SlugField(blank=True)),
+ ('color_rgb', models.CharField(blank=True, max_length=20)),
+ ('date_created', models.DateTimeField(auto_now_add=True)),
+ ('date_updated', models.DateTimeField(auto_now=True)),
+ ],
+ options={
+ 'verbose_name': 'Category',
+ 'verbose_name_plural': 'Categories',
+ },
+ ),
+ 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': 'Tag',
+ 'verbose_name_plural': 'Tags',
+ },
+ ),
+ 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/0002_auto_20211006_2025.py b/app/taxonomy/migrations/0002_auto_20211006_2025.py
new file mode 100644
index 0000000..6e8f57a
--- /dev/null
+++ b/app/taxonomy/migrations/0002_auto_20211006_2025.py
@@ -0,0 +1,28 @@
+# Generated by Django 3.2.8 on 2021-10-06 20:25
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('taxonomy', '0001_initial'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='category',
+ name='id',
+ field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
+ ),
+ migrations.AlterField(
+ model_name='luxtag',
+ name='id',
+ field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
+ ),
+ migrations.AlterField(
+ model_name='taggeditems',
+ name='id',
+ field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
+ ),
+ ]
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..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})
diff --git a/app/taxonomy/urls.py b/app/taxonomy/urls.py
new file mode 100644
index 0000000..882bd52
--- /dev/null
+++ b/app/taxonomy/urls.py
@@ -0,0 +1,13 @@
+from django.urls import path, re_path
+
+from . import views
+
+app_name = "taxonomy"
+
+urlpatterns = [
+ path(
+ r'<slug>',
+ views.CategoryDetailView.as_view(),
+ name="cat-detail"
+ ),
+]
diff --git a/app/taxonomy/views.py b/app/taxonomy/views.py
new file mode 100644
index 0000000..2d749ab
--- /dev/null
+++ b/app/taxonomy/views.py
@@ -0,0 +1,14 @@
+from django.views.generic import ListView
+from django.views.generic.detail import DetailView
+from django.contrib.syndication.views import Feed
+from django.urls import reverse
+from django.conf import settings
+
+#from paypal.standard.forms import PayPalPaymentsForm
+
+from .models import Category
+
+
+class CategoryDetailView(DetailView):
+ model = Category
+ slug_field = "slug"