Skip to content

Instantly share code, notes, and snippets.

@ksze
Last active August 29, 2015 14:02
Show Gist options
  • Save ksze/5f523f1c8fb57e432640 to your computer and use it in GitHub Desktop.
Save ksze/5f523f1c8fb57e432640 to your computer and use it in GitHub Desktop.
def add_employees(request):
# Some preparation... (skipped)
success_msg = ''
roles = get_roles()
if request.method == 'POST':
form = EmployeeForm(request.POST, roles=roles)
if form.is_valid():
# add the employees... (details omitted)
success_msg = 'yay'
# re-initialize the form
form = EmployeeForm(roles=roles)
else:
form = EmployeeForm(roles=roles)
return render(
request,
'path/to/template.html',
'form': form,
'success_msg': success_msg,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment