user profile edit name form

This commit is contained in:
Arne Schauf 2013-09-28 18:33:45 +02:00
parent d89adee989
commit 4a3751732c
3 changed files with 36 additions and 2 deletions

View File

@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
from django import forms
from django.contrib.auth.models import User
class UserProfileForm(forms.ModelForm):
class Meta:
model = User
fields = ['first_name', 'last_name', ]

View File

@ -1,5 +1,16 @@
{% extends "base.html" %}
{% load bootstrap %}
{% block content %}
<h1>Hi, {{ request.user.username }}</h1>
<h3>Your data:</h3>
<div class="row">
<div class="col-lg-4">
<form method="post" action="">
{% csrf_token %}
{{ form|bootstrap }}
<button type="submit" class="btn btn-primary">Save</button>
</form>
</div>
</div>
{% endblock %}

View File

@ -1,9 +1,22 @@
# -*- coding: utf-8 -*-
from django.views.generic import TemplateView
from django.views.generic import TemplateView, UpdateView
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from .forms import UserProfileForm
class UserProfileView(TemplateView):
class UserProfileView(UpdateView):
template_name = "accounts/user_profile.html"
model = User
fields = ['first_name', 'last_name']
form_class = UserProfileForm
def get_object(self):
return self.request.user
def get_success_url(self):
return reverse('account_profile')
def get_context_data(self, *args, **kwargs):
context = super(UserProfileView, self).get_context_data(*args, **kwargs)