From e61f3d2c4537a2670c40b33eb02231a71dfb028a Mon Sep 17 00:00:00 2001 From: lxf Date: Thu, 7 Jan 2021 16:49:29 -0500 Subject: added a photograpy section by tweaking Category model and then adding some urls --- app/taxonomy/admin.py | 3 ++ .../migrations/0005_category_description.py | 18 ++++++++++++ app/taxonomy/migrations/0006_auto_20210107_1611.py | 33 ++++++++++++++++++++++ app/taxonomy/models.py | 13 ++++++++- 4 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 app/taxonomy/migrations/0005_category_description.py create mode 100644 app/taxonomy/migrations/0006_auto_20210107_1611.py (limited to 'app/taxonomy') diff --git a/app/taxonomy/admin.py b/app/taxonomy/admin.py index 783584e..45e4e26 100644 --- a/app/taxonomy/admin.py +++ b/app/taxonomy/admin.py @@ -14,6 +14,9 @@ class CategoryAdmin(admin.ModelAdmin): 'name', 'color_rgb', 'slug', + "pluralized_name", + "description", + "intro_markdown", ), 'classes': ( 'show', diff --git a/app/taxonomy/migrations/0005_category_description.py b/app/taxonomy/migrations/0005_category_description.py new file mode 100644 index 0000000..bd2ec0b --- /dev/null +++ b/app/taxonomy/migrations/0005_category_description.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1 on 2021-01-07 15:48 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('taxonomy', '0004_auto_20201114_0757'), + ] + + operations = [ + migrations.AddField( + model_name='category', + name='description', + field=models.CharField(max_length=300, null=True), + ), + ] diff --git a/app/taxonomy/migrations/0006_auto_20210107_1611.py b/app/taxonomy/migrations/0006_auto_20210107_1611.py new file mode 100644 index 0000000..1a875f7 --- /dev/null +++ b/app/taxonomy/migrations/0006_auto_20210107_1611.py @@ -0,0 +1,33 @@ +# Generated by Django 3.1 on 2021-01-07 16:11 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('taxonomy', '0005_category_description'), + ] + + operations = [ + migrations.AddField( + model_name='category', + name='intro_html', + field=models.TextField(blank=True, null=True), + ), + migrations.AddField( + model_name='category', + name='intro_markdown', + field=models.TextField(blank=True, null=True), + ), + migrations.AlterField( + model_name='category', + name='description', + field=models.CharField(blank=True, max_length=300, null=True), + ), + migrations.AlterField( + model_name='category', + name='pluralized_name', + field=models.CharField(blank=True, max_length=60, null=True), + ), + ] diff --git a/app/taxonomy/models.py b/app/taxonomy/models.py index 4db3294..6cc1769 100644 --- a/app/taxonomy/models.py +++ b/app/taxonomy/models.py @@ -3,6 +3,8 @@ from django.urls import reverse from django.utils.translation import ugettext_lazy as _ from django.utils.functional import cached_property +from utils.util import markdown_to_html + from taggit.models import TagBase, GenericTaggedItemBase @@ -27,7 +29,10 @@ class TaggedItems(GenericTaggedItemBase): class Category(models.Model): """ Generic model for Categories """ name = models.CharField(max_length=250) - pluralized_name = models.CharField(max_length=60, null=True) + pluralized_name = models.CharField(max_length=60, null=True, blank=True) + description = models.CharField(max_length=300, null=True, blank=True) + intro_markdown = models.TextField(null=True, blank=True) + intro_html = models.TextField(null=True, blank=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) @@ -42,3 +47,9 @@ class Category(models.Model): def get_absolute_url(self): return reverse("taxonomy:cat-detail", kwargs={"slug": self.slug}) + + + def save(self, *args, **kwargs): + if self.intro_markdown: + self.intro_html = markdown_to_html(self.intro_markdown) + super(Category, self).save(*args, **kwargs) -- cgit v1.2.3-70-g09d2