The SSH host key has changed on 8 April, 2022 to this one: SHA256:573uTBSeh74kvOo0HJXi5ijdzRm8me27suzNEDlGyrQ

Added post tags

master
Gergely Polonkai 9 years ago
parent 6ada4d0a5d
commit 4cb97ed97a
  1. 2
      blog/models.py
  2. 7
      blog/templates/blog/post.html
  3. 1
      blog/urls.py
  4. 4
      blog/views.py
  5. 1
      gergelypolonkai_django/settings.py

@ -1,5 +1,6 @@
from django.db import models
from django.contrib.auth.models import User
from taggit.managers import TaggableManager
class Post(models.Model):
user = models.ForeignKey(User)
@ -8,6 +9,7 @@ class Post(models.Model):
slug = models.CharField(max_length = 100)
content = models.TextField()
draft = models.BooleanField()
tags = TaggableManager()
def __unicode__(self):
return self.title

@ -2,6 +2,13 @@
<h3>{% if title_links %}<a href="{% url 'blog:read' post.created_at.year post.created_at.month post.created_at.day post.slug %}">{% endif %}{{ post.title }}{% if title_links %}</a>{% else %}<div class="plusone-container"><div class="g-plusone" data-annotation="inline" data-size="small" data-width="300"></div></div>{% endif %}</h3>
<p class="article-date">{{ post.created_at|date:'m-d-Y :: H:i' }} by {{ post.user.first_name }} {{ post.user.last_name }}</p>
{{ post.content|safe }}
{% if post.tags.all %}
<p class="article-tags">Tags:
{% for tag in post.tags.all %}
<a href="{% url 'blog:taglist' tag.slug %}">{{ tag.name }}</a>
{% endfor %}
</p>
{% endif %}
{% if not title_links %}
<div class="g-plus" data-action="share" data-height="15"></div>
{% endif %}

@ -4,6 +4,7 @@ from blog import views
urlpatterns = patterns('',
url(r'^$', views.index, name='index'),
url(r'^feed$', views.feed, name='feed'),
url(r'^tag/(?P<tag>.*)$', views.taglist, name='taglist'),
url(r'^(?P<year>\d+)/(?P<month>\d+)/(?P<day>\d+)/(?P<slug>[^/]+)$', views.read, name='read'),
url(r'^resume', views.resume, name='resume'),
url(r'^about', views.resume, name='about'),

@ -10,6 +10,10 @@ def read(request, year, month, day, slug):
post = get_object_or_404(Post, created_at__year=int(year), created_at__month=int(month), created_at__day=int(day), slug=slug);
return render(request, 'blog/view.html', {'post': post})
def taglist(request, tag):
posts = Post.objects.filter(tags__slug=tag)
return render(request, 'blog/listing.html', {'posts': posts})
def feed(request):
return render(request, 'blog/feed.xml', {})

@ -127,6 +127,7 @@ INSTALLED_APPS = (
'django.contrib.staticfiles',
'django.contrib.admin',
'compressor',
'taggit',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'blog',

Loading…
Cancel
Save