from django.shortcuts import render, redirect
from .forms import CustomBookForm
from .models import Book
def create_book(request):
if request.method == 'POST':
form = CustomBookForm(request.POST)
if form.is_valid():
book = Book(
title=form.cleaned_data['title'],
author=form.cleaned_data['author'],
publication_date=form.cleaned_data['publication_date']
)
book.save()
return redirect('success_page')
else:
form = CustomBookForm()
return render(request, 'create_book.html', {'form': form})