Add basic Child list page example.

This commit is contained in:
Christopher Charbonneau Wells 2017-08-16 09:12:49 -04:00
parent 6e2112b6b5
commit 8d9eef2915
4 changed files with 50 additions and 8 deletions

View File

@ -25,8 +25,8 @@
<li class="nav-item{% if request.path == '/' %} active{% endif %}"> <li class="nav-item{% if request.path == '/' %} active{% endif %}">
<a class="nav-link" href="{% url 'index' %}">Home</a> <a class="nav-link" href="{% url 'index' %}">Home</a>
</li> </li>
<li class="nav-item{% if request.path == '/child/add/' %} active{% endif %}"> <li class="nav-item{% if request.path == '/children/' %} active{% endif %}">
<a class="nav-link" href="{% url 'child-add' %}">Add Child</a> <a class="nav-link" href="{% url 'child-list' %}">Children</a>
</li> </li>
</ul> </ul>
<form class="form-inline my-2 my-lg-0"> <form class="form-inline my-2 my-lg-0">
@ -39,7 +39,7 @@
</div> </div>
</nav> </nav>
<div class="container" style="padding: 3rem 1.5rem; text-align: center;"> <div class="container" style="padding: 3rem 1.5rem;">
{% block content %}{% endblock %} {% block content %}{% endblock %}
</div> </div>
</body> </body>

View File

@ -0,0 +1,35 @@
{% extends 'core/base.html' %}
{% load i18n widget_tweaks %}
{% block title %}Children{% endblock %}
{% block content %}
<h1>Children</h1>
<table class="table table-striped table-hover">
<thead class="thead-inverse">
<tr>
<th>#</th>
<th>First Name</th>
<th>Last Name</th>
<th>Birth Date</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for child in object_list %}
<tr>
<th scope="row">{{ child.id }}</th>
<td><a href="{% url 'child-update' child.id %}">{{ child.first_name }}</a></td>
<td>{{ child.last_name }}</td>
<td>{{ child.birth_date }}</td>
<td><a href="{% url 'child-update' child.id %}">modify<a/> | <a href="{% url 'child-delete' child.id %}">delete<a/></td>
</tr>
{% empty %}
<tr>
<th colspan="4">No children added.</th>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}

View File

@ -7,9 +7,11 @@ from . import views
urlpatterns = [ urlpatterns = [
url(r'^$', views.Index.as_view(), name='index'), url(r'^$', views.Index.as_view(), name='index'),
url(r'child/add/$', views.ChildAdd.as_view(), name='child-add'),
url(r'child/(?P<pk>[0-9]+)/$', views.ChildUpdate.as_view(), url(r'children/$', views.ChildList.as_view(), name='child-list'),
url(r'children/add/$', views.ChildAdd.as_view(), name='child-add'),
url(r'children/(?P<pk>[0-9]+)/$', views.ChildUpdate.as_view(),
name='child-update'), name='child-update'),
url(r'child/(?P<pk>[0-9]+)/delete/$', views.ChildDelete.as_view(), url(r'children/(?P<pk>[0-9]+)/delete/$', views.ChildDelete.as_view(),
name='child-delete'), name='child-delete'),
] ]

View File

@ -3,6 +3,7 @@ from __future__ import unicode_literals
from django.views.generic.base import TemplateView from django.views.generic.base import TemplateView
from django.views.generic.edit import CreateView, UpdateView, DeleteView from django.views.generic.edit import CreateView, UpdateView, DeleteView
from django.views.generic.list import ListView
from .models import Child from .models import Child
@ -11,16 +12,20 @@ class Index(TemplateView):
template_name = 'core/index.html' template_name = 'core/index.html'
class ChildList(ListView):
model = Child
class ChildAdd(CreateView): class ChildAdd(CreateView):
model = Child model = Child
fields = ['first_name', 'last_name', 'birth_date'] fields = ['first_name', 'last_name', 'birth_date']
success_url = '/' success_url = '/children'
class ChildUpdate(UpdateView): class ChildUpdate(UpdateView):
model = Child model = Child
fields = ['first_name', 'last_name', 'birth_date'] fields = ['first_name', 'last_name', 'birth_date']
success_url = '/' success_url = '/children'
class ChildDelete(DeleteView): class ChildDelete(DeleteView):