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

View File

@ -6,5 +6,10 @@ from django.conf.urls import url
from . import views from . import views
urlpatterns = [ 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 __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 .models import Baby
class IndexView(TemplateView): class Index(TemplateView):
template_name = 'core/index.html' 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