Add basic Baby model forms.

This commit is contained in:
Christopher Charbonneau Wells 2017-08-15 16:24:55 -04:00
parent b66b1c5af2
commit 9dc0821c3f
4 changed files with 42 additions and 6 deletions

View File

@ -0,0 +1,12 @@
{% extends 'core/base.html' %}
{% block title %}Add a Baby{% endblock %}
{% block content %}
<h1>Add a Baby</h1>
<form method="POST" class="post-form">
{% csrf_token %}
{{ form.as_p }}
<button type="submit" class="save btn btn-default">Save</button>
</form>
{% endblock %}

View File

@ -12,7 +12,7 @@
</head>
<body style="padding-top: 5rem;">
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
<a class="navbar-brand" href="#">Navbar</a>
<a class="navbar-brand" href="#"><span class="text-info">Baby</span> Blotter</a>
<button class="navbar-toggler" type="button" data-toggle="collapse"
data-target="#navbarsExampleDefault"
aria-controls="navbarsExampleDefault" aria-expanded="false"
@ -23,10 +23,10 @@
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
<ul class="navbar-nav mr-auto">
<li class="nav-item{% if request.path == '/' %} active{% endif %}">
<a class="nav-link" href="#">Home</a>
<a class="nav-link" href="{% url 'index' %}">Home</a>
</li>
<li class="nav-item{% if request.path == '/baby/add' %} active{% endif %}">
<a class="nav-link" href="/baby/add">Add Baby</a>
<li class="nav-item{% if request.path == '/baby/add/' %} active{% endif %}">
<a class="nav-link" href="{% url 'baby-add' %}">Add Baby</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">

View File

@ -6,5 +6,10 @@ from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.IndexView.as_view(), name='index'),
url(r'^$', views.Index.as_view(), name='index'),
url(r'baby/add/$', views.BabyAdd.as_view(), name='baby-add'),
url(r'baby/(?P<pk>[0-9]+)/$', views.BabyUpdate.as_view(),
name='baby-update'),
url(r'baby/(?P<pk>[0-9]+)/delete/$', views.BabyDelete.as_view(),
name='baby-delete'),
]

View File

@ -2,7 +2,26 @@
from __future__ import unicode_literals
from django.views.generic.base import TemplateView
from django.views.generic.edit import CreateView, UpdateView, DeleteView
from .models import Baby
class IndexView(TemplateView):
class Index(TemplateView):
template_name = 'core/index.html'
class BabyAdd(CreateView):
model = Baby
fields = ['first_name', 'last_name', 'birth_date']
success_url = '/'
class BabyUpdate(UpdateView):
model = Baby
fields = ['first_name', 'last_name', 'birth_date']
success_url = '/'
class BabyDelete(DeleteView):
model = Baby