A
A
Alexander Savchuk2015-09-14 06:03:29
Django
Alexander Savchuk, 2015-09-14 06:03:29

How to make a form on which you can edit fields from two models?

There is one view on which you need to display a form with the following fields:

  • Email (User)
  • Skype (Profile)
  • phone (profile)

(The name of the model is indicated in brackets)
I understand that you can create a class inherited from django.forms.Form, define the fields I need in it, and use FormView, but as for me, this is a crutch. Is there a more elegant way?
Thank you in advance for your response.
PS auth.UserDo not offer to expand :-)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
sim3x, 2015-09-14
@sim3x

<form>
{% csrf_token %}
{{ model_form_user }}
{{ model_form_profile }}

<button type="submit">

And in ModelForm we define fields
Extend auth.User not suggest
then suffer further with such questions
PS:
elite
https://ru.wiktionary.org/wiki/%D1%8D%D0%BB%D0%B5%...

D
dake1231, 2015-09-14
@dake1231

Can create a general model

I
IvanOne, 2015-09-14
@IvanOne

What is the purpose of the form? If you create a new user, then you still have to fiddle with the form, and determine what this field will be stored in this model, but that field to another model here is just the Form that will help you. If another object is created on the basis of this, then it probably makes sense to design a model for these purposes. Of course, you can do without the form classes at all, and do everything manually in the view.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question