blog/views.py
in the post_new
and post_edit
methods:post_list
that displays only published blog posts (those with non-empty published_date
).blog/templates/blog/base.html
in the header. We don't want to show our list of drafts to everybody, so we'll put it inside the {% if user.is_authenticated %}
check, right after the button for adding new posts.blog/urls.py
we add:blog/views.py
:posts = Post.objects.filter(published_date__isnull=True).order_by('created_date')
makes sure that we take only unpublished posts (published_date__isnull=True
) and order them by created_date
(order_by('created_date')
).blog/templates/blog/post_draft_list.html
and add the following:post_list.html
, right?http://127.0.0.1:8000/drafts/
you will see the list of unpublished posts.blog/templates/blog/post_detail.html
and change these lines:{% else %}
line here. That means, that if the condition from {% if post.published_date %}
is not fulfilled (so if there is no published_date
), then we want to do the line <a class="btn btn-default" href="{% url 'post_publish' pk=post.pk %}">Publish</a>
. Note that we are passing a pk
variable in the {% url %}
.blog/urls.py
):blog/views.py
):Post
model we wrote a method publish
. It looked like this:post_detail
page!blog/templates/blog/post_detail.html
once again and add this line:blog/urls.py
):blog/views.py
and add this code:.delete()
. It is as simple as that!redirect
.