working on news detail view
This commit is contained in:
parent
628488c1dc
commit
ef364f42cf
|
@ -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
|
||||
|
|
9
news/templates/news_detail.html
Normal file
9
news/templates/news_detail.html
Normal 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 %}
|
|
@ -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 %}
|
||||
|
|
|
@ -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'),
|
||||
]
|
||||
|
|
|
@ -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'
|
||||
|
||||
|
|
Loading…
Reference in a new issue