Q:

update / edit function in django one-to-one models

i've made an edit form in django, and i have trouble in my update function.  There is a relational models that using one-to-one relationship.  When i run this function, data in User models stored properly, but not in the UserProfile models.  
This is my urls.py
url(r'^update_user/(?P<pk>\d+)$', views.update_user, name='update_user'),

This is my models:
class UserProfile(models. Model):
    user = models. OneToOneField(User)

    CATEGORY_CHOICES = (
        ('admin','Admin'),
        ('user','User'),
        )
    hak_akses = models. CharField(max_length=100, choices = CATEGORY_CHOICES)

    def __unicode__(self):
        return self.user.username

This is my views.py
def update_user(request, pk, template_name='form_user.html'):
    related = User.objects.select_related().all()
    user = get_object_or_404(related, pk=pk)
   # profile = get_object_or_404(UserProfile, pk=pk)
    if request. POST:
        user_form = UserForm(data=request. POST, instance=user)
        profile_form = UserProfileForm(data=request. POST, instance=user)
        if user_form.is_valid() and profile_form.is_valid():
            user.set_password(user.password)
            user.save()
            profile = profile_form.save(commit=False)
            profile.user = user
            profile.save()
            return redirect('manajemen_user')

    else:
        user_form = UserForm(instance=user)
        profile_form = UserProfileForm(instance=user)

    return render_to_response(template_name, {
        'user_form': user_form, 'profile_form': profile_form,
    }, context_instance=RequestContext(request))

This is my forms:
class UserForm(forms. ModelForm):
    password = forms. CharField(widget=forms. PasswordInput())

    class Meta:
        model = User
        fields = ('username', 'password')

class UserProfileForm(forms. ModelForm):
    CATEGORY_CHOICES = (
        ('admin','Admin'),
        ('user','User'),
        )
    hak_akses = forms. ChoiceField(choices = CATEGORY_CHOICES)
    class Meta:
        model = UserProfile
        fields = ('hak_akses',)

And this is my form templates html:
<form name="tambah_user" class="form-horizontal style-form" method="POST">{% csrf_token %}
            <div class="form-group">

              <label class="col-sm-2 col-sm-2 control-label">Nama User</label>
              <div class="col-sm-10">
                <!--  <input type="text" class='form-control'> -->
                {{ user_form.username }}
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 col-sm-2 control-label">Password</label>
              <div class="col-sm-10">
                {{ user_form.password }}
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 col-sm-2 control-label">Hak Akses</label>
              <div class="col-sm-10">
                {{ profile_form.hak_akses }}
                <br><br><br>
                <button type="submit" class="btn btn-theme">Submit</button>
              </div>
            </div>
          </form>

why data in User Models updated properly but not in UserProfile models ? 
what's the solution?  

thank you very much

A:

You should construct UserProfileForm form with the UserProfile instance instead of User:
profile = UserProfile.objects.filter(user=user).first()
...
profile_form = UserProfileForm(data=request. POST, instance=profile)
...
profile_form = UserProfileForm(instance=profile)

If you are sure that profile is already exist then you can write:
profile = user.userprofile

instead of the filter().first() call.