def search_add(request): global flag1 global flag2 global flag4 global author_flag flag1 = False flag2 = False flag4 = False author_flag = False if request.POST: post = request.POST try: author = Author.objects.get(AuthorID=post["AuthorID"]) if 'save_author' in post: author_flag = True return render_to_response('search_add_author.html',{'author_flag':author_flag}) except: if 'save_book' in post: return render_to_response('search_add_author.html') elif 'save_author' in post: post = request.POST if post["AuthorID"]=='' or post["Name"]=='' or post["Age"]=='' or post["Country"]=='' : flag4 = True return render_to_response('search_add_author.html',{'blank_flag':flag4}) else: author =Author( AuthorID = post["AuthorID"], Name = post["Name"], Age = post["Age"], Country = post["Country"]) author.save() return render_to_response('search_add_book.html') author = Author.objects.get(AuthorID=post["AuthorID"]) if post["ISBN"]=='' or post["Title"]=='' or post["Publisher"]=='' or post["PublishDate"]=='' or post["Price"]=='' : flag2 = True return render_to_response('search_add_book.html',{'blank_flag':flag2}) else: new_book = Book( ISBN = post["ISBN"], Title = post["Title"], AuthorID = author, Publisher = post["Publisher"], PublishDate= post["PublishDate"], Price = post["Price"]) new_book.save() flag1 = True return render_to_response('search_add_book.html',{'flag':flag1})