display fields of form within another form

10 views
Skip to first unread message

marcelle Kouam

unread,
Jun 8, 2015, 4:36:23 PM6/8/15
to django...@googlegroups.com
hello
I have a problem.
I have an application user and another employee. i want to display all the fields of user in my employee forms. now, I just redisplay my form user in my form employee like that in my template:

{{ form_1.as_p }}
{{ form.as_p }}


this is my view employee:


def add(request, template_name='employee/add.html'):
if request.method == 'POST':
form = EmployeeAddForm(data=request.POST)
form_1 = UserRegisterForm(data = request.POST)
if form.is_valid() and form_1.is_valid():
user = form_1.save()
employee = form.save(commit=False)
employee.user = user
user.set_password(user.password)
user.save()
employee.save()

else:
print(form.errors)
else:
form = EmployeeAddForm()
form_1 = UserRegisterForm()
return render(request, template_name, {'form': form, 'form_1' : form_1, 'added': added})


but I think that it'is not the best method. can you give me another method which will be more intelligent.
thanks

Reply all
Reply to author
Forward
0 new messages