Updated Views

parent b2e59bcd
from django.http import HttpResponse from django.shortcuts import render
from django.views.generic import ListView, DetailView
from .models import *
# Create your views here. # Create your views here.
def index(request): def Home_Views(request):
return HttpResponse('hello world') return render(request, 'home.html', {})
\ No newline at end of file
class Books_Views(ListView):
model = Book
template_name = "books.html"
context_object_name= 'Books_list'
class Authors_Views(ListView):
model = Author
template_name = "authors.html"
context_object_name='Authors_list'
class Authors_Details_Views(DetailView):
template_name = "author_details.html"
model = Author
def get_context_data(self, **kwargs):
context = super(Authors_Details_Views, self).get_context_data(**kwargs)
context ['bookdetail'] = Book.objects.filter(author=self.get_object())
return context
class Book_Details_Views(DetailView):
template_name = "book_details.html"
model = Book
def get_context_data(self, **kwargs):
context = super(Book_Details_Views, self).get_context_data(**kwargs)
context ['authordetail'] = Author.objects.filter(book=self.get_object())
return context
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment