mirror of https://github.com/snachodog/mybuddy.git
Add basic Child list page example.
This commit is contained in:
parent
6e2112b6b5
commit
8d9eef2915
|
@ -25,8 +25,8 @@
|
|||
<li class="nav-item{% if request.path == '/' %} active{% endif %}">
|
||||
<a class="nav-link" href="{% url 'index' %}">Home</a>
|
||||
</li>
|
||||
<li class="nav-item{% if request.path == '/child/add/' %} active{% endif %}">
|
||||
<a class="nav-link" href="{% url 'child-add' %}">Add Child</a>
|
||||
<li class="nav-item{% if request.path == '/children/' %} active{% endif %}">
|
||||
<a class="nav-link" href="{% url 'child-list' %}">Children</a>
|
||||
</li>
|
||||
</ul>
|
||||
<form class="form-inline my-2 my-lg-0">
|
||||
|
@ -39,7 +39,7 @@
|
|||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="container" style="padding: 3rem 1.5rem; text-align: center;">
|
||||
<div class="container" style="padding: 3rem 1.5rem;">
|
||||
{% block content %}{% endblock %}
|
||||
</div>
|
||||
</body>
|
||||
|
|
|
@ -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 %}
|
|
@ -7,9 +7,11 @@ from . import views
|
|||
|
||||
urlpatterns = [
|
||||
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'),
|
||||
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'),
|
||||
]
|
||||
|
|
|
@ -3,6 +3,7 @@ from __future__ import unicode_literals
|
|||
|
||||
from django.views.generic.base import TemplateView
|
||||
from django.views.generic.edit import CreateView, UpdateView, DeleteView
|
||||
from django.views.generic.list import ListView
|
||||
|
||||
from .models import Child
|
||||
|
||||
|
@ -11,16 +12,20 @@ class Index(TemplateView):
|
|||
template_name = 'core/index.html'
|
||||
|
||||
|
||||
class ChildList(ListView):
|
||||
model = Child
|
||||
|
||||
|
||||
class ChildAdd(CreateView):
|
||||
model = Child
|
||||
fields = ['first_name', 'last_name', 'birth_date']
|
||||
success_url = '/'
|
||||
success_url = '/children'
|
||||
|
||||
|
||||
class ChildUpdate(UpdateView):
|
||||
model = Child
|
||||
fields = ['first_name', 'last_name', 'birth_date']
|
||||
success_url = '/'
|
||||
success_url = '/children'
|
||||
|
||||
|
||||
class ChildDelete(DeleteView):
|
||||
|
|
Loading…
Reference in New Issue