diff options
author | Jonathan DeMasi <jrdemasi@gmail.com> | 2020-03-02 21:40:33 -0700 |
---|---|---|
committer | Jonathan DeMasi <jrdemasi@gmail.com> | 2020-03-02 21:40:33 -0700 |
commit | 7078ade87556b727f4ff1183b0a2ea240f0ad9f4 (patch) | |
tree | 5132a4462802ff0784c4d3204f9365c675c99ac8 | |
parent | 5f1250cc5928e47a2710f5edf9dc98287a4d5f1b (diff) | |
download | jthanio-7078ade87556b727f4ff1183b0a2ea240f0ad9f4.tar jthanio-7078ade87556b727f4ff1183b0a2ea240f0ad9f4.tar.gz jthanio-7078ade87556b727f4ff1183b0a2ea240f0ad9f4.tar.bz2 jthanio-7078ade87556b727f4ff1183b0a2ea240f0ad9f4.tar.lz jthanio-7078ade87556b727f4ff1183b0a2ea240f0ad9f4.tar.xz jthanio-7078ade87556b727f4ff1183b0a2ea240f0ad9f4.tar.zst jthanio-7078ade87556b727f4ff1183b0a2ea240f0ad9f4.zip |
category support backend. Tags fronend
-rw-r--r-- | .vscode/settings.json | 3 | ||||
-rw-r--r-- | blog/migrations/0003_blogtagindexpage.py | 25 | ||||
-rw-r--r-- | blog/migrations/0004_blogcategory.py | 23 | ||||
-rw-r--r-- | blog/models.py | 28 | ||||
-rw-r--r-- | blog/templates/blog/blog_post.html | 37 | ||||
-rw-r--r-- | blog/templates/blog/blog_tag_index_page.html | 23 | ||||
-rw-r--r-- | jthanio/static/css/jthanio.css | 3 |
7 files changed, 114 insertions, 28 deletions
diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..84c8f83 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.pythonPath": "venv/bin/python3" +}
\ No newline at end of file diff --git a/blog/migrations/0003_blogtagindexpage.py b/blog/migrations/0003_blogtagindexpage.py new file mode 100644 index 0000000..7b6ad76 --- /dev/null +++ b/blog/migrations/0003_blogtagindexpage.py @@ -0,0 +1,25 @@ +# Generated by Django 3.0.3 on 2020-03-03 04:28 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('wagtailcore', '0045_assign_unlock_grouppagepermission'), + ('blog', '0002_auto_20200302_2331'), + ] + + operations = [ + migrations.CreateModel( + name='BlogTagIndexPage', + fields=[ + ('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')), + ], + options={ + 'abstract': False, + }, + bases=('wagtailcore.page',), + ), + ] diff --git a/blog/migrations/0004_blogcategory.py b/blog/migrations/0004_blogcategory.py new file mode 100644 index 0000000..d7e3cd4 --- /dev/null +++ b/blog/migrations/0004_blogcategory.py @@ -0,0 +1,23 @@ +# Generated by Django 3.0.3 on 2020-03-03 04:40 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('blog', '0003_blogtagindexpage'), + ] + + operations = [ + migrations.CreateModel( + name='BlogCategory', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=255)), + ], + options={ + 'verbose_name_plural': 'blog categories', + }, + ), + ] diff --git a/blog/models.py b/blog/models.py index 71f4b32..fb9c828 100644 --- a/blog/models.py +++ b/blog/models.py @@ -7,6 +7,7 @@ from wagtail.search import index from modelcluster.fields import ParentalKey from modelcluster.contrib.taggit import ClusterTaggableManager from taggit.models import TaggedItemBase +from wagtail.snippets.models import register_snippet class BlogIndexPage(Page): intro = RichTextField(blank=True) @@ -49,3 +50,30 @@ class BlogPost(Page): FieldPanel('intro'), FieldPanel('body'), ] + +class BlogTagIndexPage(Page): + + def get_context(self, request): + + # Filter by tag + tag = request.GET.get('tag') + blogpages = BlogPost.objects.filter(tags__name=tag) + + # Update template context + context = super().get_context(request) + context['blogpages'] = blogpages + return context + +@register_snippet +class BlogCategory(models.Model): + name = models.CharField(max_length=255) + + panels = [ + FieldPanel('name') + ] + + def __str__(self): + return self.name + + class Meta: + verbose_name_plural = 'blog categories' diff --git a/blog/templates/blog/blog_post.html b/blog/templates/blog/blog_post.html index 93602ae..9a2f318 100644 --- a/blog/templates/blog/blog_post.html +++ b/blog/templates/blog/blog_post.html @@ -14,9 +14,6 @@ <!-- Title --> <h1 class="mt-4">{{ page.title }}</h1> - - <hr> - <!-- Date/Time --> <p>Posted on {{ page.date }} in CATEGORY</p> @@ -38,36 +35,20 @@ <!-- Sidebar Widgets Column --> <div class="col-md-4"> - <!-- Categories Widget --> + <!-- Tags Widget --> <div class="card my-4"> - <h5 class="card-header">Categories</h5> + <h5 class="card-header">Tags</h5> <div class="card-body"> <div class="row"> <div class="col-lg-6"> <ul class="list-unstyled mb-0"> - <li> - <a href="#">Web Design</a> - </li> - <li> - <a href="#">HTML</a> - </li> - <li> - <a href="#">Freebies</a> - </li> - </ul> - </div> - <div class="col-lg-6"> - <ul class="list-unstyled mb-0"> - <li> - <a href="#">JavaScript</a> - </li> - <li> - <a href="#">CSS</a> - </li> - <li> - <a href="#">Tutorials</a> - </li> - </ul> + {% if page.tags.all.count %} + {% for tag in page.tags.all %} + <span class="badge badge-primary"><a href="{% slugurl 'tags' %}?tag={{ tag }}">{{ tag }}</a></span> + {% endfor %} + {% else %} + No tags for this post + {% endif %} </div> </div> </div> diff --git a/blog/templates/blog/blog_tag_index_page.html b/blog/templates/blog/blog_tag_index_page.html new file mode 100644 index 0000000..b431272 --- /dev/null +++ b/blog/templates/blog/blog_tag_index_page.html @@ -0,0 +1,23 @@ +{% extends "base.html" %} +{% load wagtailcore_tags %} + +{% block content %} + + {% if request.GET.tag|length %} + <h4>Showing pages tagged "{{ request.GET.tag }}"</h4> + {% endif %} + + {% for blogpage in blogpages %} + <p> + <strong><a href="{% pageurl blogpage %}">{{ blogpage.title }}</a></strong><br /> + <small>Revised: {{ blogpage.latest_revision_created_at }}</small><br /> + {% if blogpage.author %} + <p>By {{ blogpage.author.profile }}</p> + {% endif %} + </p> + + {% empty %} + No pages found with that tag. + {% endfor %} + +{% endblock %}
\ No newline at end of file diff --git a/jthanio/static/css/jthanio.css b/jthanio/static/css/jthanio.css index e69de29..bde2ab6 100644 --- a/jthanio/static/css/jthanio.css +++ b/jthanio/static/css/jthanio.css @@ -0,0 +1,3 @@ +.badge-primary a { + color: white; +} |