Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use a <a href="https://docs.djangoproject.com/en/1.6/topics/forms/modelforms/" rel="nofollow"><code>ModelForm</code></a> instead of a regular <code>Form</code>. A <code>ModelForm</code> can be associated with an instance, which is the used to prepopulate the form. If you want to update both the <code>User</code> and the profile, you can use two <code>ModelForm</code>s in one view. For example:</p> <pre><code>class UserModelForm(forms.ModelForm): repassword = ... # additional fields that have no represenation in the model class Meta: model = User fields = ["username", "password", ] # ... def clean(self): # ... your validation logic class ProfileForm(forms.ModelForm): class Meta: model = YourProfileModel fields = [] # ... </code></pre> <p>Then use both in the view:</p> <pre><code>def usermodify(request, user): # mod_user = ... user_form = UserModelForm(request.POST or None, instance=mod_user) profile_form = ProfileForm(request.POST or None, instance=mod_user.get_profile()) if user_form.is_valid() and profile_form.is_valid(): user_form.save() # this saves to the associated mod_user, as passed via the `instance` argument profile_form.save() # ... redirect etc. return render(..., {'user_form': user_form, 'profile_form': profile_form}) # pass both forms to the template </code></pre> <p>In the template, put both forms <em>inside of one <code>&lt;form&gt;</code> tag</em>. Be sure that they don't have conflicting field names, or <a href="https://docs.djangoproject.com/en/dev/ref/forms/api/#prefixes-for-forms" rel="nofollow">use a <code>prefix</code>.</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload