Skip to content

Instantly share code, notes, and snippets.

@jcockhren
Created February 2, 2014 02:05
Show Gist options
  • Save jcockhren/8762001 to your computer and use it in GitHub Desktop.
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.
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']
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)
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