Tagged under {{ object.slug }}
+-
+ {% for entry in object.post_set.all %}
+
- {{ entry.title }} + {% endfor %} +
diff --git a/contributr/contriblog/admin.py b/contributr/contriblog/admin.py index 00bbacf..f8f0c9f 100644 --- a/contributr/contriblog/admin.py +++ b/contributr/contriblog/admin.py @@ -1,6 +1,6 @@ from django.contrib import admin -from .models import Post +from .models import * class PostAdmin(admin.ModelAdmin): @@ -9,3 +9,4 @@ class PostAdmin(admin.ModelAdmin): admin.site.register(Post, PostAdmin) +admin.site.register(Tag) diff --git a/contributr/contriblog/migrations/0002_auto_20150924_1705.py b/contributr/contriblog/migrations/0002_auto_20150924_1705.py new file mode 100644 index 0000000..19ae07d --- /dev/null +++ b/contributr/contriblog/migrations/0002_auto_20150924_1705.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('contriblog', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='Tag', + fields=[ + ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('slug', models.SlugField(unique=True, max_length=200)), + ], + ), + migrations.AddField( + model_name='post', + name='tags', + field=models.ManyToManyField(to='contriblog.Tag'), + ), + ] diff --git a/contributr/contriblog/models.py b/contributr/contriblog/models.py index 70da3bd..f9cdd72 100644 --- a/contributr/contriblog/models.py +++ b/contributr/contriblog/models.py @@ -2,6 +2,12 @@ from django.core.urlresolvers import reverse +# Tag class +class Tag(models.Model): + slug = models.SlugField(max_length=200, unique=True) + + def __str__(self): + return self.slug # Custom queryset manager that only displays posts that have publish set to true. class PostQuerySet(models.QuerySet): @@ -18,6 +24,7 @@ class Post(models.Model): edited_date = models.DateTimeField(auto_now=True) publish = models.BooleanField(default=False) slug = models.SlugField(max_length=200, unique=True) + tags = models.ManyToManyField(Tag) objects = PostQuerySet.as_manager() diff --git a/contributr/contriblog/templates/contriblog/detail.html b/contributr/contriblog/templates/contriblog/detail.html index fab54fc..8bc2c5f 100644 --- a/contributr/contriblog/templates/contriblog/detail.html +++ b/contributr/contriblog/templates/contriblog/detail.html @@ -9,8 +9,16 @@
created on {{ object.created_date|date }}, by {{ object.author }}
+ ++ created on {{ object.created_date|date }}, by {{ object.author }} | Tagged under + {% for tag in object.tags.all %} + {{ tag.slug }}{% if not forloop.last %},{% endif %} + {% endfor %} +
+{{ object.body|markdown }}
+ {% endblock %} diff --git a/contributr/contriblog/templates/contriblog/index.html b/contributr/contriblog/templates/contriblog/index.html index 1ad1456..fa5206c 100644 --- a/contributr/contriblog/templates/contriblog/index.html +++ b/contributr/contriblog/templates/contriblog/index.html @@ -11,7 +11,13 @@created on {{ object.created_date|date }}, by {{ object.author }}
+ ++ created on {{ object.created_date|date }}, by {{ object.author }} | Tagged under + {% for tag in object.tags.all %} + {{ tag.slug }}{% if not forloop.last %},{% endif %} + {% endfor %} +
{{ object.body|markdown }}
diff --git a/contributr/contriblog/templates/contriblog/tag.html b/contributr/contriblog/templates/contriblog/tag.html new file mode 100644 index 0000000..4f4e097 --- /dev/null +++ b/contributr/contriblog/templates/contriblog/tag.html @@ -0,0 +1,11 @@ +{% extends "base.html" %} +{% block content %} +