I'm trying to create a user profile for my users with Django. Overall it seems to have mostly worked and I am able to see everything correct in the admin page. On my actual HTML page I correctly see the model fields that I need, however they aren't populated with any data, and the data I put in won't actually save even though it says it does.
views.py
class DemoUserEditView(UpdateView):
form_class = DemoUserEditForm
template_name = "user/profile.html"
view_name = 'account_profile'
success_url = '/member/'
def get_object(self):
return self.request.user
def form_valid(self, form):
form.save()
messages.add_message(self.request, messages.INFO, 'User profile updated')
return super(DemoUserEditView, self).form_valid(form)
account_profile = login_required(DemoUserEditView.as_view())
models.py.
class UserProfile(models.Model):
user = models.OneToOneField(User, primary_key=True, on_delete=models.CASCADE)
avatar_url = models.CharField(max_length=256, blank=True, null=True)
skills = models.CharField(max_length=256, blank=True, null=True)
avatarpic = models.ImageField(_('avatar photo'),
blank=True, null=True,
upload_to=user_directory_path, validators=[validate_img_extension])
Bio = models.TextField(_('Bio'),
max_length=200, blank=True, null=True, unique=False)
EDUCATION_CHOICES = (
('0', "Didn't complete High School"),
('1', 'High School or GED'),
('2', 'Associate Degree'),
('3', 'Batchlors Degree'),
('4', 'Masters Degree'),
('5', 'PhD Degree'),
('6', 'Professional Degree'),
)
Education = models.CharField(_('Education'),
max_length=100, blank=True, null=False,
choices=EDUCATION_CHOICES, unique=False,
help_text="Level of Education")
urls.py
url(r'^accounts/', include('allauth.urls')),
url(r'^accounts/profile/$', 'base.views.account_profile', name='account_profile'),
I'm trying to use Generic Views, and I thought UpdateView would be the appropriate tag for this. I have read through the Generic View docs as well as several this stackoverflow question, and this one. My big problem is that I'm not getting anymore error messages and it says the form is valid and saving, but it's not and i'm not sure what else to even try.
So how can I populate my modelform with the existing user data?