working on news detail view
This commit is contained in:
parent
628488c1dc
commit
ef364f42cf
|
@ -14,6 +14,7 @@ class NewsItem(CreatedUpdatedModel):
|
||||||
content = models.TextField()
|
content = models.TextField()
|
||||||
public = models.BooleanField(default=False)
|
public = models.BooleanField(default=False)
|
||||||
published_at = models.DateTimeField()
|
published_at = models.DateTimeField()
|
||||||
|
slug = models.SlugField()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.title
|
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 %}
|
{% block content %}
|
||||||
{% for item in news_items %}
|
{% for item in news_items %}
|
||||||
<div>
|
<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>
|
</div>
|
||||||
{{ item.content|commonmark }}
|
{{ item.content|commonmark }}
|
||||||
{% if not forloop.last %}
|
{% if not forloop.last %}
|
||||||
|
|
|
@ -4,4 +4,5 @@ from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^$', views.NewsIndex.as_view(), name='index'),
|
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
|
from . import models
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,3 +7,9 @@ class NewsIndex(ListView):
|
||||||
queryset = models.NewsItem.objects.public()
|
queryset = models.NewsItem.objects.public()
|
||||||
template_name = 'news_index.html'
|
template_name = 'news_index.html'
|
||||||
context_object_name = 'news_items'
|
context_object_name = 'news_items'
|
||||||
|
|
||||||
|
|
||||||
|
class NewsDetail(DetailView):
|
||||||
|
model = models.NewsItem
|
||||||
|
template_name = 'news_detail.html'
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue