#view.py---------------------------------------------------------------------------------------------------------------------
from django.shortcuts import render, get_object_or_404
from django.views.generic import ListView, DetailView, CreateView, UpdateView, DeleteView
from .models import Post, Category, Comment
from .forms import PostForm, EditForm, CommentForm
from django.urls import reverse_lazy, reverse
from django.http import HttpResponseRedirect
#Import Pagination Stuff
from django.core.paginator import Paginator
class HomeView(ListView):
# paginate_by = 5
model = Post
template_name = 'home.html'
cats = Category.objects.all()
#ordering = ['-post_date']
ordering = ['-id']
def get_context_data(self, *args, **kwargs):
cat_menu = Category.objects.all()
context = super(HomeView, self).get_context_data(*args, **kwargs)
context["cat_menu"] = cat_menu
return context
home.html-----------------------------------------------------------------------------------------------------------------------
{% extends ‘base.html’ %}
{% block content %}
Posts
-
{% for post in object_list %}
-
{{ post.title }}
- <a href="{% url 'category' post.category|slugify %}">{{ post.category }}</a> - {{ post.author.first_name }} {{ post.author.last_name }} - {{ post.post_date }} <small> {% if user.is_authenticated %} {% if user.id == post.author.id %} - <a href="{% url 'update_post' post.pk %}">(Edit)</a> <a href="{% url 'delete_post' post.pk %}">(Delete)</a> {% endif %} {% endif %} </small> <br/> {{ post.snippet }}</li>
{% endfor %}
{% endblock %}