forms - Django related models and UpdateView fields -


I created a model (UserSettings) to extend the user model of the Django through a one-to-fide (As recommended by the documentation):

  class UserSettings (models.Model): user = models.OneToOneField (user, primary_key = true) subscribeToMails = models.BooleanField (default = true) [...]   

I want to provide a way for my users to edit some of their profile data, some of which Received are stored in the model (email address), and the rest are in the User Sncitrn model. How can I go about doing this?

I thought in two ways: Add another one-tofild to the user settings models for the e-mail address field; Or UpdateView is overriding the get_queryset () method (but I'm not sure how to) is there any best or recommended way to do this? So far this is the way to see my view:

  class editUser (UpdateView): Model = UserSettings fields = ('emailVisible', 'subscribeToMails',' mpPopupNotif ',' mpEmailNotif ',' Avatar Template_name = 'user / edit.html' def get_object (auto): return UserSettings.objects.get (user_id = self.request.user) def get_success_url (auto): return reverse_lazy (' User:  

Use this solution:

Combine both user And UserSettings as follows:

  class EmployeeEditForm (forms.ModelForm): # The fields you want to edit are class_name = forms.CharField (required = false, label = _ ('first name')) last_name = forms.CharField (required = incorrect, label = _ ('last name')) Category meta: Model = UserSettings fields = ( users  and  UserSettings  objects can access  views.   

PI S:

  user = request.user usersettings = user.usersettings   

You can now type user object You can edit:

  user.first_name = request.POST ['first_name'] us Er.last_name = request.POST ['last_name'] user.save ()   

and UserSettings edit like this:

  usersettings.subscribeToMails = Requests POST ['subscribeToMails'] usersettings.save ()    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -