In chapter 08 of this series, we covered how to input data through the front end of the application. In this chapter, I will show you how to empty the form data after clicking the save button.
- Import render redirect to allow you the page to be redirected to another after saving the data.
from django.shortcuts import render, redirect
Add return redirect
immediately after form.save()
2. Now to empty the form, we will reload the page to give us a new and empty form, thus clearing the form and getting it ready to input a new record.
We will add this if condition
to the entry view in views.py
if form.is_valid():
form.save()
return redirect('/add_invoice')