Extends User profile in Django -


i'm trying make editable user profile , found, how add fields it... need make editable first , last name, email , 1 field change user password. got user , additional fields in form...

how can realise that?

my model:

import pil  django.db import models django.contrib.auth.models import user pil import image django.db import models  # create models here.  class userprofile(models.model):       user = models.onetoonefield(user)     user_phone = models.charfield(max_length=140, blank=true, null=true)     user_picture = models.imagefield(upload_to='users', blank=true, null=true)     user_balance = models.integerfield(default=0)  user.profile = property(lambda u: userprofile.objects.get_or_create(user=u) [0]) 

my forms.py :

from django import forms userprofile.models import userprofile  class userprofileform(forms.modelform):     class meta:         model = userprofile         fields = ('user', 'user_phone', 'user_picture', 'user_balance') 

my view:

from django.shortcuts import render, render_to_response django.shortcuts import httpresponseredirect, http404 django.template import requestcontext django.contrib.auth.decorators import login_required django.core.context_processors import csrf  # create views here. userprofile.forms import userprofileform userprofile.models import userprofile  def user_profile(request):     if request.method == 'post':         form = userprofileform(request.post, instance=request.user.profile)         if form.is_valid():             form.save()             return httpresponseredirect('/')     else:         user = request.user         profile = user.profile         form = userprofileform(instance=profile)      args = {}     args.update(csrf(request))      args['form'] = form      return render_to_response('profile.html', args) 

and template:

{% field in form %}     {{ field.error }}  {% endfor %}  <form action="/users/profile/" method="post">{% csrf_token %} {{ form.as_ul }}  <input type="submit" value="update" />  </form> 

if cant call user fields userprofile can create form user model

class userform(forms.modelform):     class meta:         model = user         fields = ('last_name', 'email', 'password') 

you need show both forms in view also. check example modelform onetoonefield in django password field might need this, check examples.

https://docs.djangoproject.com/en/1.5/topics/auth/customizing/#a-full-example


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -