Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can copy fields over if you like, and dual-update them as you have in the above, but that's not the purpose of the profile. It's supposed to handle fields not in the original auth.User, since you shouldn't need to edit that model directly. You mentioned "extending User" above - you aren't actually inheriting from auth.User, are you? I highly don't recommend that.</p> <p>Update:</p> <p>See <a href="http://birdhouse.org/blog/2009/06/27/django-profiles/" rel="nofollow noreferrer">this reference material</a>. It is using the same syntax as you to do user-updating inside the profile. </p> <p>Update 2:</p> <p>The example is for <strong>edit profile</strong>, not create profile. Looking at the code in profile.views.create_profile:</p> <pre><code>if request.method == 'POST': form = form_class(data=request.POST, files=request.FILES) if form.is_valid(): profile_obj = form.save(commit=False) profile_obj.user = request.user profile_obj.save() </code></pre> <p>So it saves the form <em>first</em>, then sets <strong>user</strong>, then saves the profile.</p> <p>That means you can't set the user values in the form.save, you need to do it in the profile's model.save:</p> <pre><code># in sumaConnectUser: from django.db.models.base import ObjectDoesNotExist class sumaConnectUser(models.Model): ... def save( self, *args, **kwargs ): s = super(sumaConnectUser,self).save( *args, **kwargs ) try: u = s.user u.first_name = self.first_name u.last_name = self.last_name u.save() except ObjectDoesNotExist: pass return s </code></pre> <p>Basically, by looking at the code in profile.views.create_profile, we are <em>positive</em> that it <em>eventually</em> calls save on the profile <em>after</em> it has set <code>user</code>. It might not be the first time, so we need to trap that case and forget about it. Because eventually, it'll get called and trigger our save-to-user code. The upshot is that no matter what forms you have in the future for this user-profile, it'll always save back to the underlying user.</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.
 

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