Created
February 2, 2014 02:05
-
-
Save jcockhren/8762001 to your computer and use it in GitHub Desktop.
Currently, on successful POST, the form isn't propulated with the newer values.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django import forms | |
from django.core.exceptions import ValidationError | |
from apps.content.models import Profile | |
from apps.content.models import CustomUser | |
class UserForm(forms.ModelForm): | |
class Meta: | |
model = CustomUser | |
fields = ['first_name', | |
'last_name', | |
'email'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
from django.contrib.auth.models import AbstractUser | |
class CustomUser(AbstractUser): | |
company = models.CharField(max_length=30, blank=True, null=True) | |
phone_number = models.CharField(max_length=15, blank=True, null=True) | |
website = models.URLField(blank=True, null=True) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from forms import UserForm | |
from apps.content.models import CustomUser | |
class SettingsView(UpdateView): | |
model = CustomUser | |
form_class = UserForm | |
template_name = 'account/settings.html' | |
success_url = '/account/settings/' | |
fields = ['first_name', | |
'last_name', | |
'email', | |
'company'] | |
def get_initial(self): | |
return model_to_dict(CustomUser.objects.get(id=self.request.user.id)) | |
def get_object(self): | |
return CustomUser.objects.get(id=self.request.user.id) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment