Skip to content

Commit

Permalink
Create views for Blog index, categories and post details
Browse files Browse the repository at this point in the history
  • Loading branch information
pablodiegoss committed May 26, 2024
1 parent c23d5ec commit e29f5c6
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/blog/views.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,37 @@
from django.shortcuts import render

from blog.models import Post

PREVIEW_SIZE=300
def blog_index(request):

posts = Post.objects.all().order_by("-created")
context = {
"posts": posts,
"PREVIEW_SIZE": PREVIEW_SIZE,
}
return render(request, "blog/index.jinja2", context)

def blog_category(request, category):

posts = Post.objects.filter(
categories__name__contains=category
).order_by("-created")

context = {
"category": category,
"posts": posts,
"PREVIEW_SIZE": PREVIEW_SIZE,
}

return render(request, "blog/category.jinja2", context)

def blog_detail(request, pk):

post = Post.objects.get(pk=pk)

context = {
"post": post,
}

return render(request, "blog/detail.jinja2", context)

0 comments on commit e29f5c6

Please sign in to comment.