Add m2m relation to custom role
Custom role can be now added by typing the custom role name and selecting if the role name is board member or not. Added also error page redirection if something fails in Kaehmyform validation.
This commit is contained in:
+11
-9
@@ -120,16 +120,18 @@ def kaehmy_submit(request, *args, **kwargs):
|
||||
"""Submit Kaehmy form."""
|
||||
form = KaehmyForm_Form(request.POST)
|
||||
if form.is_valid():
|
||||
print("Formi oli validi")
|
||||
form.save()
|
||||
# custom_name = form.cleaned_data.get('custom_role_name')
|
||||
# custom_is_board = form.cleaned_data.get('custom_role_is_board')
|
||||
# custom_role = CustomKaehmyRole(
|
||||
# name=custom_name, is_board=custom_is_board)
|
||||
# custom_role.save()
|
||||
application = form.save()
|
||||
custom_name = form.cleaned_data.get('custom_role_name')
|
||||
custom_is_board = form.cleaned_data.get('custom_role_is_board')
|
||||
custom_role = CustomKaehmyRole(
|
||||
name=custom_name, is_board=custom_is_board)
|
||||
custom_role.save()
|
||||
application.custom_roles.add(custom_role)
|
||||
else:
|
||||
return HttpResponseRedirect('/')
|
||||
# return render(request, 'error.html', {'error': form.errors})
|
||||
context = {
|
||||
'errors': form.errors
|
||||
}
|
||||
return render(request, 'error.html', context)
|
||||
return HttpResponseRedirect('/kaehmy')
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user