Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem is that you're trying to create or update fields in a User object that doesn't even exist yet. So the other fields aren't really updated because they aren't associated to any primary keys of the child fields. </p> <p>Every time you're instantiating a new model field, you have to make sure you're saving so that a child model field has an id (primary key) to associate with. </p> <p>You need something more like this:</p> <pre><code>def save(self): user = User( username = self.cleaned_data['username'], email = self.cleaned_data['email1'], first_name = self.cleaned_data['first_name'], last_name = self.cleaned_data['last_name'], ) ## save user so we get an id user.save() ## make sure we have a user.id if user.id: ## this doesn't save the password, just updates the working instance user.set_password(self.cleaned_data['password1']) user.profile = Profile( primary_phone = self.cleaned_data['phone'], ) ## save the profile so we get an id user.profile.save() ## make sure we have a profile.id if user.profile.id: user.profile.address = Address( country = self.cleaned_data['country'], province = self.cleaned_data['province'], city = self.cleaned_data['city'], postal_code = self.cleaned_data['postal_code'], street1 = self.cleaned_data['street1'], street2 = self.cleaned_data['street2'], street3 = self.cleaned_data['street3'], ) ## save the profile address user.profile.address.save() ## final save to commit password and profile changes user.save() return user </code></pre> <p>This cascading <code>save()</code> thing you have going on here just doesn't feel right. You're prone to way too many errors there, if any of the fields doesn't save you'll end up with a partially complete user instance and posisbly end up with duplicates if the user has to go back and try again. Not fun! </p> <p><strong>Edit:</strong> Removed the 2nd half of this because it was not accurate.</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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