Django 1.4 Creating Editing User Account Settings

Some prerequisites, I am developing a user profile for our Django database system, and I am currently trying to create a view page so that the user can edit their account settings (outside the admin page). I searched for a lot of sources, most of which recommend using .get_profile (), but this did not work in my program no matter what approach I try (as far as I know and what has been done). So far I have used the django main pages for .get_profile () to see how to use .get_profile () correctly and find the AUTH_PROFILE_MODULE parameter (I will specify my settings a bit).
Using this site: http://www.turnkeylinux.org/blog/django-profileI found some other methods of using .get_profile (), but still nothing worked. (I will not add the rest of the links I tried, as I could continue for some time)

Back to the question, can anyone recommend a method that will work, so that I can get information about users, to set some default values, to maintain their current settings, if they prefer not to edit them and update only new values.

So far I: (hope all relevant parts)

file directory: ~ / Documents / project1

settings.py

AUTH_PROFILE_MODULE = "accounts.Account"

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `

File Location: Project1 / Account

models.py

# additional model to incorporate our custom fields to the auth user model                                                                                   
class Account(models.Model):
    userLink = models.OneToOneField(User)      #link (pointer) to the users other     information in User model                                                  
    birthdate = models.DateField(blank = True) # True makes this field optional                                                                              
    gender = models.CharField(max_length = 1, choices = GENDER_CHOICE, null = True)

    def __unicode__(self):            # define a unicode for the user to access                                                                              
        return u'%s %s' % (self.userLink.first_name, self.userLink.last_name)   # return first and last name

# custom Form to change user account information (can't be a modelForm)                                                                                      
class EditAccountForm(forms.Form):
    gender = forms.CharField(max_length = 1)#, choices = GENDER_CHOICE, null = True)                                                                         
    birthdate = forms.DateField(widget = SelectDateWidget()) # True makes this field   optional

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

views.py

# Account settings view                                                                                                                                      
@login_required
def AccountSettings(request):
    sluggedSettingError = request.GET.get('error', '') # error message with slugged character                                                                
    settingError = sluggedSettingError.replace('-', ' ')
    settingForm = AdditionalForm(request.POST or None) # variable is called in     edit_user.html                                                                
    # might want to have some way to create a new profile if the account doesn't exist                                                                       
    userSettings = Account.objects.filter(userLink=request.user)
#    userSettings = request.user.get_profile() # returns the current settings of the     users profile                                                           
#### Currently trying to get it to let me use get_profile() ########                                                                                         
    print "userLink = %s" % userSettings#.user                                                                                                               
#    print "Gender = %s" % userSettings.gender # testing print                                                                                               
    if request.method == 'POST':
#        if settingForm.is_valid():                                                                                                                          
#            settingForm.save();                                                                                                                             
        return HttpResponseRedirect('/')
    return render_to_response("user_settings.html", {'settingForm': settingForm,   'settingError': settingError}, context_instance = RequestContext(request))
#        gender = request.POST['gender']  # pass in the gender variable from post                                                                            
#        birthdate = request.POST['birthdate']   # pass in the birthdate from post        

.get_profile() , userLink, "userSettings". , , , userSettings.gender, userSettings.birthdate .. , , ( if Django).

, , get_profile(). get_profile() ( ),    "" . : , , id, userLink

, userLink, "", , , - django.docs, , . : : https://bitbucket.org/filmaster/filmaster-test/src/1618b18003ed/film20/userprofile/views.py , .

, .get_profile() , , , . , , , , . - , . , - , , , , .

!

+3
2

, , get_profile() :

user.get_profile()

,

request.user.get_profile()

Django Docs. ,

get_profile() , .

, ...

+6

user.get_profile() , , , OneToOne , user.profile

0

All Articles