working on news detail view

This commit is contained in:
Thomas Steen Rasmussen 2016-06-05 23:20:06 +02:00
parent 628488c1dc
commit ef364f42cf
5 changed files with 19 additions and 2 deletions

View file

@ -14,6 +14,7 @@ class NewsItem(CreatedUpdatedModel):
content = models.TextField()
public = models.BooleanField(default=False)
published_at = models.DateTimeField()
slug = models.SlugField()
def __str__(self):
return self.title

View file

@ -0,0 +1,9 @@
{% extends 'base.html' %}
{% load commonmark %}
{% block content %}
<div>
<h3>{{ news_item.title }} <small>{{ news_item.published_at|date:"Y-m-d" }}</small></h3>
</div>
{{ news_item.content|commonmark }}
{% endblock %}

View file

@ -4,7 +4,7 @@
{% block content %}
{% for item in news_items %}
<div>
<h3>{{ item.title }} <small>{{ item.published_at|date:"Y-m-d" }}</small></h3>
<h3><a href="{% reverse 'news:detail' slug=item.slug %}">{{ item.title }}</a> <small>{{ item.published_at|date:"Y-m-d" }}</small></h3>
</div>
{{ item.content|commonmark }}
{% if not forloop.last %}

View file

@ -4,4 +4,5 @@ from . import views
urlpatterns = [
url(r'^$', views.NewsIndex.as_view(), name='index'),
url(r'(?P<slug>[-_\w+]+)/$', NewsDetail.as_view(), name='detail'),
]

View file

@ -1,4 +1,4 @@
from django.views.generic import ListView
from django.views.generic import ListView, DetailView
from . import models
@ -7,3 +7,9 @@ class NewsIndex(ListView):
queryset = models.NewsItem.objects.public()
template_name = 'news_index.html'
context_object_name = 'news_items'
class NewsDetail(DetailView):
model = models.NewsItem
template_name = 'news_detail.html'