Refactor model "Baby" as "Child".

This commit is contained in:
Christopher Charbonneau Wells 2017-08-16 08:49:58 -04:00
parent 12e700eb74
commit 6e2112b6b5
9 changed files with 37 additions and 37 deletions

View File

@ -3,12 +3,12 @@ from __future__ import unicode_literals
from rest_framework import serializers
from core.models import Baby, DiaperChange, Feeding, Note, Sleep, TummyTime
from core.models import Child, DiaperChange, Feeding, Note, Sleep, TummyTime
class BabySerializer(serializers.HyperlinkedModelSerializer):
class ChildSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Baby
model = Child
fields = ('first_name', 'last_name', 'birth_date')

View File

@ -4,11 +4,11 @@ from __future__ import unicode_literals
from django.conf.urls import url, include
from rest_framework import routers
from .views import (BabyViewSet, DiaperChangeViewSet, FeedingViewSet,
from .views import (ChildViewSet, DiaperChangeViewSet, FeedingViewSet,
NoteViewSet, SleepViewSet, TummyTimeViewSet)
router = routers.DefaultRouter()
router.register(r'babies', BabyViewSet)
router.register(r'children', ChildViewSet)
router.register(r'diaper-changes', DiaperChangeViewSet)
router.register(r'feedings', FeedingViewSet)
router.register(r'notes', NoteViewSet)

View File

@ -3,20 +3,20 @@ from __future__ import unicode_literals
from rest_framework import viewsets
from core.models import Baby, DiaperChange, Feeding, Note, Sleep, TummyTime
from core.models import Child, DiaperChange, Feeding, Note, Sleep, TummyTime
from core.utils import filter_by_params
from .serializers import (BabySerializer, DiaperChangeSerializer,
from .serializers import (ChildSerializer, DiaperChangeSerializer,
FeedingSerializer, NoteSerializer, SleepSerializer,
TummyTimeSerializer,)
class BabyViewSet(viewsets.ModelViewSet):
queryset = Baby.objects.all()
serializer_class = BabySerializer
class ChildViewSet(viewsets.ModelViewSet):
queryset = Child.objects.all()
serializer_class = ChildSerializer
def get_queryset(self):
params = ['first_name', 'last_name']
return filter_by_params(self.request, Baby, params)
return filter_by_params(self.request, Child, params)
class DiaperChangeViewSet(viewsets.ModelViewSet):

View File

@ -3,11 +3,11 @@ from __future__ import unicode_literals
from django.contrib import admin
from .models import Baby, DiaperChange, Feeding, Note, Sleep, TummyTime
from .models import Child, DiaperChange, Feeding, Note, Sleep, TummyTime
@admin.register(Baby)
class BabyAdmin(admin.ModelAdmin):
@admin.register(Child)
class ChildAdmin(admin.ModelAdmin):
list_display = ('first_name', 'last_name', 'birth_date',)
list_filter = ('last_name',)
search_fields = ('first_name', 'last_name', 'birth_date',)

View File

@ -6,7 +6,7 @@ from django.db import models
from .utils import duration_string
class Baby(models.Model):
class Child(models.Model):
first_name = models.CharField(max_length=255)
last_name = models.CharField(max_length=255)
birth_date = models.DateField(blank=False, null=False)
@ -16,14 +16,14 @@ class Baby(models.Model):
class Meta:
default_permissions = ('view', 'add', 'change', 'delete')
ordering = ['last_name', 'first_name']
verbose_name_plural = 'Babies'
verbose_name_plural = 'Children'
def __str__(self):
return '{} {}'.format(self.first_name, self.last_name)
class DiaperChange(models.Model):
baby = models.ForeignKey('Baby', related_name='diaper_change')
baby = models.ForeignKey('Child', related_name='diaper_change')
time = models.DateTimeField(blank=False, null=False)
wet = models.BooleanField()
solid = models.BooleanField()
@ -45,7 +45,7 @@ class DiaperChange(models.Model):
class Feeding(models.Model):
baby = models.ForeignKey('Baby', related_name='feeding')
baby = models.ForeignKey('Child', related_name='feeding')
start = models.DateTimeField(blank=False, null=False)
end = models.DateTimeField(blank=False, null=False)
type = models.CharField(max_length=255, choices=[
@ -73,7 +73,7 @@ class Feeding(models.Model):
class Note(models.Model):
baby = models.ForeignKey('Baby', related_name='note')
baby = models.ForeignKey('Child', related_name='note')
note = models.TextField()
time = models.DateTimeField(auto_now=True)
@ -88,7 +88,7 @@ class Note(models.Model):
class Sleep(models.Model):
baby = models.ForeignKey('Baby', related_name='sleep')
baby = models.ForeignKey('Child', related_name='sleep')
start = models.DateTimeField(blank=False, null=False)
end = models.DateTimeField(blank=False, null=False)
@ -108,7 +108,7 @@ class Sleep(models.Model):
class TummyTime(models.Model):
baby = models.ForeignKey('Baby', related_name='tummy_time')
baby = models.ForeignKey('Child', related_name='tummy_time')
start = models.DateTimeField(blank=False, null=False)
end = models.DateTimeField(blank=False, null=False)
milestone = models.CharField(max_length=255, blank=True)

View File

@ -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 == '/baby/add/' %} active{% endif %}">
<a class="nav-link" href="{% url 'baby-add' %}">Add Baby</a>
<li class="nav-item{% if request.path == '/child/add/' %} active{% endif %}">
<a class="nav-link" href="{% url 'child-add' %}">Add Child</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">

View File

@ -1,10 +1,10 @@
{% extends 'core/base.html' %}
{% load i18n widget_tweaks %}
{% block title %}Add a Baby{% endblock %}
{% block title %}Add a Child{% endblock %}
{% block content %}
<h1>Add a Baby</h1>
<h1>Add a Child</h1>
<form role="form" method="post">
{% csrf_token %}
{% for field in form %}

View File

@ -7,9 +7,9 @@ from . import views
urlpatterns = [
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'),
url(r'child/add/$', views.ChildAdd.as_view(), name='child-add'),
url(r'child/(?P<pk>[0-9]+)/$', views.ChildUpdate.as_view(),
name='child-update'),
url(r'child/(?P<pk>[0-9]+)/delete/$', views.ChildDelete.as_view(),
name='child-delete'),
]

View File

@ -4,24 +4,24 @@ 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
from .models import Child
class Index(TemplateView):
template_name = 'core/index.html'
class BabyAdd(CreateView):
model = Baby
class ChildAdd(CreateView):
model = Child
fields = ['first_name', 'last_name', 'birth_date']
success_url = '/'
class BabyUpdate(UpdateView):
model = Baby
class ChildUpdate(UpdateView):
model = Child
fields = ['first_name', 'last_name', 'birth_date']
success_url = '/'
class BabyDelete(DeleteView):
model = Baby
class ChildDelete(DeleteView):
model = Child