from django.contrib import messages
from django.shortcuts import render, get_object_or_404, redirect
from django.http import HttpResponseRedirect


from .forms import PostForm
from .models import Post


def index(request):
    queryset = Post.objects.all()
    context = {'object_list': queryset, 'title': 'List'}
    return render(request, 'blog/index.html', context)


def form_create(request):
    form = PostForm(request.POST or None)
    if form.is_valid():
        instance = form.save(commit=False)
        instance.save()
        messages.success(request, 'Successfully Created YO')
        return HttpResponseRedirect(instance.get_absolute_url())
    context = {"form": form}
    return render(request, 'blog/form_create.html', context)


def detail(request, id=None):
    obj = get_object_or_404(Post, id=id)
    context = {'obj': obj}
    return render(request, 'blog/detail.html', context)


def update(request, id=None):
    instance = get_object_or_404(Post, id=id)
    form = PostForm(request.POST or None, instance=instance)
    if form.is_valid():
        instance = form.save(commit=False)
        instance.save()
        messages.success(request, 'Update Saved')
        return HttpResponseRedirect(instance.get_absolute_url())

    context = {'title': instance.title, 'instance': instance, 'form': form}
    return render(request, 'blog/form_create.html', context)


def delete(request, id=None):
    instance = get_object_or_404(Post, id=id)
    instance.delete()
    messages.success(request, 'Successfully deleted')
    return redirect('blog:index')

@@ -29,16 +29,89 @@
 essages%0A
+from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger%0A
 from dja
@@ -301,16 +301,21 @@
 queryset
+_list
  = Post.
@@ -328,35 +328,349 @@
 s.all()%0A    
-context = %7B
+paginator = Paginator(queryset_list, 5)%0A    page_var = %22p%22%0A    page = request.GET.get(page_var)%0A    try:%0A        queryset = paginator.page(page)%0A    except PageNotAnInteger:%0A        queryset = paginator.page(1)%0A    except EmptyPage:%0A        queryset = paginator.page(paginator.num_pages)%0A    context = %7B'page_var': page_var, 
 'object_list

add paginator