On Jun 22, 5:11 pm, raj <nano.ri...@gmail.com> wrote:
> I think I'm starting to get the hang of it a little. I was able to
> extract the data from the profile and set it as the initial value.
> From what I understand, you would like me to set each user field one
> at a time, but if I have 20-30 fields that need to be updated at once,
> I'm at a loss. The way that I have my files set up is that I have a
> view with the following code:
> ### views.py ###
> def profileFields(request):
> user = request.user
> if request.method == 'POST':
> form = userProf(request.POST)
> if form.is_valid():
> user = form.save(request.POST, user)
> return HttpResponseRedirect('/user/update/success')
> else:
> form = userProf(instance=user.get_profile())
> return render_to_response("/home/oneadmin/webapps/oneadmin/
> oneadmin/templates/oneadmissions/profile.html", {'form': form},
> context_instance = RequestContext(request))
>
> now my userProf form module has the following save function:
> def save(self, new_data, user):
> user.get_profile().colleges = new_data['colleges']
> .....dozen other new_data fields would go here...
> user.save()
> return user
>
> From what I understand, you want me to put the save information in the
> views.py file, but my actual form class is in a different document. So
> i decided that it would be better to put it there. Am I on the right
> track? Why isn't any information actually being updated?
>
> On Jun 22, 5:05 am, Herman Schistad <herman.schis...@gmail.com> wrote:
>
>
>
>
>
>
>
> > On Wed, Jun 22, 2011 at 10:14, raj <nano.ri...@gmail.com> wrote:
> > > If I didn't have the url
> > > set up in this manner, how would I manage to extract the userprofile?
>
> > If you have the "AuthenticationMiddleware" activated you would use request.user
> > This returns a User object, which you then can use to further edit things.
>
> > E.g.
> > user = request.user
> > user.username = "Somethingnew"
> > user.save()
>
> > Or, as Kevin Renskers said, you would create a seperate model for the
> > userprofile if you wanted to extend it. Here you will need to get the
> > user profile with user.get_profile() and remember to set the
> > following: AUTH_PROFILE_MODULE = "myapp.mysiteprofile"
>
> > Then you could use the above example like this:
> > user = request.user
> > user.get_profile().homepage = "http://example.org"
> > user.save()
>
> > --
> > With regards, Herman Schistad
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment