Some background,
I ve been designing a user profile for our Django database system and am currently trying to create a views page to allow the user to edit their account settings (outside of the admin page). I have searched numerous sources, most of which recommend using .get_profile(), but this has not worked in my program no matter what approach I try (to my knowledge and research done). So far I have used the django main pages for .get_profile() to see how to properly use .get_profile() and found the AUTH_PROFILE_MODULE setting ( I will specify my settings in a bit).
Using this site:
http://www.turnkeylinux.org/blog/django-profile I found out some other methods of using .get_profile() but still nothing has worked. (I won t add the rest of the links i ve tried as I could go on for a while)
Back to the question, can anyone recommend a method that would work so that I can obtain the users information to set up some default values to maintain their current settings if they choose not to edit them and only update the ones with new submitted values.
迄今为止,我已经(全心全意地所有相关部分)
file directory: ~/Documents/project1
settings.py
AUTH_PROFILE_MODULE = "accounts.Account"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~ ~~~~~
File location: project1/accounts
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
由于该守则目前是我所介绍的,试图通过现有账户进行查询,直到找到一个配对用户链接,然后将其保留到一个可变的“用户解决方案”。 我采取的办法是将这一变量作为用户解决方案。 性别、用户分布。 出生日期等进入每个用户环境,如果更新和确定以前的价值(如果在Django功能中做了一系列陈述或部分内容),则会发生变化。
I m not sure if this is the most efficient method, or if I should revert back to the get_profile() method. When I was using get_profile() (as it is typed currently in the commented out line) I got the following error Cannot resolve keyword user into field. Choices are: birthdate, gender, id, userLink
I also tried this approach with a new database using userLink defined as "user" instead to match what the django.docs website specified but still got an error about the Account not existing. I tried creating a try: and except: approach from https://bitbucket.org/filmaster/filmaster-test/src/1618b18003ed/film20/userprofile/views.py to handle this error but this also did not yield any positive results.
I am out of ideas on how to get .get_profile() to work, and can t think of anything to allow me to access the users stored information so that it can be edited in a form by them. I m not sure I understand how to utilize it properly at this point and feel like I m just running around in circles at this point. If anyone can help me with this I d appreciate it. I tried to give as much relevant information as I could, but if you need something else to help me out let me know and I will try to include it as soon as I can.
Thanks in advance!