Commit 51e5837d authored by James Esguerra's avatar James Esguerra

Added edit button for nickname

parent d291048e
...@@ -10,9 +10,13 @@ class UserForm(forms.ModelForm): ...@@ -10,9 +10,13 @@ class UserForm(forms.ModelForm):
class Meta: class Meta:
model = User model = User
fields = ['profile_photo'] fields = ['profile_photo']
label = {
'profile_photo': '',
} class NicknameForm(forms.ModelForm):
class Meta:
model = User
fields = ['nickname']
class KeyForm(forms.ModelForm): class KeyForm(forms.ModelForm):
class Meta: class Meta:
......
...@@ -15,4 +15,5 @@ urlpatterns = [ ...@@ -15,4 +15,5 @@ urlpatterns = [
path('add_itemT', views.ShowAddItemT, name='add_itemT'), path('add_itemT', views.ShowAddItemT, name='add_itemT'),
path('edit_itemT/<int:pk>', views.ShowEditItemT, name='edit_itemT'), path('edit_itemT/<int:pk>', views.ShowEditItemT, name='edit_itemT'),
path('delete_itemT/<int:pk>', views.ShowDeleteItemT, name='delete_itemT'), path('delete_itemT/<int:pk>', views.ShowDeleteItemT, name='delete_itemT'),
path('edit_nickname', views.ShowEditNickname, name='edit_nickname'),
] ]
...@@ -4,6 +4,7 @@ from django.http import HttpResponse ...@@ -4,6 +4,7 @@ from django.http import HttpResponse
from .forms import ( from .forms import (
HomeForm, HomeForm,
UserForm, UserForm,
NicknameForm,
KeyForm, KeyForm,
ItemsThisWeekForm, ItemsThisWeekForm,
ItemsTodayForm, ItemsTodayForm,
...@@ -49,6 +50,19 @@ def ShowProfile(request): ...@@ -49,6 +50,19 @@ def ShowProfile(request):
return render(request, 'profile.html', context) return render(request, 'profile.html', context)
def ShowEditNickname(request):
user = User.objects.get(pk=1)
form = NicknameForm(instance=user)
if request.method == 'POST':
form = NicknameForm(request.POST, instance=user)
if form.is_valid():
form.save()
return redirect('profile')
return render(request, 'edit_nickname.html', {'form': form})
def ShowKey(request): def ShowKey(request):
key_list = Key.objects.all() key_list = Key.objects.all()
return render(request, 'key.html', {'key_list': key_list}) return render(request, 'key.html', {'key_list': key_list})
......
{% extends 'base.html' %}
{% load static %}
{% block title %} Key {% endblock %}
{% block header %} Key {% endblock %}
{% block content %}
<form action='' method='POST'>
{% csrf_token %}
{{ form }}
<input type='submit' name='Submit' value='Save'>
</form>
{% endblock %}
...@@ -9,9 +9,13 @@ ...@@ -9,9 +9,13 @@
<div id='profile'> <div id='profile'>
<div> <div>
<p><b>Nickname:</b> {{ user.nickname }} </p> <p>
<b>Nickname:</b>
{{ user.nickname }}
<a href='{% url 'edit_nickname' %}'><button type='button'>Edit</button></a>
</p>
<br> <br>
<p><b>Bio:</b> {{ user.bio }}</p> <p><b>Bio:</b>{{ user.bio }}</p>
</div> </div>
<div id='image-container'> <div id='image-container'>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment