user profile edit name form
This commit is contained in:
parent
d89adee989
commit
4a3751732c
10
nsupdate/accounts/forms.py
Normal file
10
nsupdate/accounts/forms.py
Normal 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', ]
|
||||
|
@ -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 %}
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user