mirror of https://github.com/snachodog/mybuddy.git
Refactor model "Baby" as "Child".
This commit is contained in:
parent
12e700eb74
commit
6e2112b6b5
|
@ -3,12 +3,12 @@ from __future__ import unicode_literals
|
||||||
|
|
||||||
from rest_framework import serializers
|
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:
|
class Meta:
|
||||||
model = Baby
|
model = Child
|
||||||
fields = ('first_name', 'last_name', 'birth_date')
|
fields = ('first_name', 'last_name', 'birth_date')
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,11 +4,11 @@ from __future__ import unicode_literals
|
||||||
from django.conf.urls import url, include
|
from django.conf.urls import url, include
|
||||||
from rest_framework import routers
|
from rest_framework import routers
|
||||||
|
|
||||||
from .views import (BabyViewSet, DiaperChangeViewSet, FeedingViewSet,
|
from .views import (ChildViewSet, DiaperChangeViewSet, FeedingViewSet,
|
||||||
NoteViewSet, SleepViewSet, TummyTimeViewSet)
|
NoteViewSet, SleepViewSet, TummyTimeViewSet)
|
||||||
|
|
||||||
router = routers.DefaultRouter()
|
router = routers.DefaultRouter()
|
||||||
router.register(r'babies', BabyViewSet)
|
router.register(r'children', ChildViewSet)
|
||||||
router.register(r'diaper-changes', DiaperChangeViewSet)
|
router.register(r'diaper-changes', DiaperChangeViewSet)
|
||||||
router.register(r'feedings', FeedingViewSet)
|
router.register(r'feedings', FeedingViewSet)
|
||||||
router.register(r'notes', NoteViewSet)
|
router.register(r'notes', NoteViewSet)
|
||||||
|
|
12
api/views.py
12
api/views.py
|
@ -3,20 +3,20 @@ from __future__ import unicode_literals
|
||||||
|
|
||||||
from rest_framework import viewsets
|
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 core.utils import filter_by_params
|
||||||
from .serializers import (BabySerializer, DiaperChangeSerializer,
|
from .serializers import (ChildSerializer, DiaperChangeSerializer,
|
||||||
FeedingSerializer, NoteSerializer, SleepSerializer,
|
FeedingSerializer, NoteSerializer, SleepSerializer,
|
||||||
TummyTimeSerializer,)
|
TummyTimeSerializer,)
|
||||||
|
|
||||||
|
|
||||||
class BabyViewSet(viewsets.ModelViewSet):
|
class ChildViewSet(viewsets.ModelViewSet):
|
||||||
queryset = Baby.objects.all()
|
queryset = Child.objects.all()
|
||||||
serializer_class = BabySerializer
|
serializer_class = ChildSerializer
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
params = ['first_name', 'last_name']
|
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):
|
class DiaperChangeViewSet(viewsets.ModelViewSet):
|
||||||
|
|
|
@ -3,11 +3,11 @@ from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.contrib import admin
|
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)
|
@admin.register(Child)
|
||||||
class BabyAdmin(admin.ModelAdmin):
|
class ChildAdmin(admin.ModelAdmin):
|
||||||
list_display = ('first_name', 'last_name', 'birth_date',)
|
list_display = ('first_name', 'last_name', 'birth_date',)
|
||||||
list_filter = ('last_name',)
|
list_filter = ('last_name',)
|
||||||
search_fields = ('first_name', 'last_name', 'birth_date',)
|
search_fields = ('first_name', 'last_name', 'birth_date',)
|
||||||
|
|
|
@ -6,7 +6,7 @@ from django.db import models
|
||||||
from .utils import duration_string
|
from .utils import duration_string
|
||||||
|
|
||||||
|
|
||||||
class Baby(models.Model):
|
class Child(models.Model):
|
||||||
first_name = models.CharField(max_length=255)
|
first_name = models.CharField(max_length=255)
|
||||||
last_name = models.CharField(max_length=255)
|
last_name = models.CharField(max_length=255)
|
||||||
birth_date = models.DateField(blank=False, null=False)
|
birth_date = models.DateField(blank=False, null=False)
|
||||||
|
@ -16,14 +16,14 @@ class Baby(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
default_permissions = ('view', 'add', 'change', 'delete')
|
default_permissions = ('view', 'add', 'change', 'delete')
|
||||||
ordering = ['last_name', 'first_name']
|
ordering = ['last_name', 'first_name']
|
||||||
verbose_name_plural = 'Babies'
|
verbose_name_plural = 'Children'
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return '{} {}'.format(self.first_name, self.last_name)
|
return '{} {}'.format(self.first_name, self.last_name)
|
||||||
|
|
||||||
|
|
||||||
class DiaperChange(models.Model):
|
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)
|
time = models.DateTimeField(blank=False, null=False)
|
||||||
wet = models.BooleanField()
|
wet = models.BooleanField()
|
||||||
solid = models.BooleanField()
|
solid = models.BooleanField()
|
||||||
|
@ -45,7 +45,7 @@ class DiaperChange(models.Model):
|
||||||
|
|
||||||
|
|
||||||
class Feeding(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)
|
start = models.DateTimeField(blank=False, null=False)
|
||||||
end = models.DateTimeField(blank=False, null=False)
|
end = models.DateTimeField(blank=False, null=False)
|
||||||
type = models.CharField(max_length=255, choices=[
|
type = models.CharField(max_length=255, choices=[
|
||||||
|
@ -73,7 +73,7 @@ class Feeding(models.Model):
|
||||||
|
|
||||||
|
|
||||||
class Note(models.Model):
|
class Note(models.Model):
|
||||||
baby = models.ForeignKey('Baby', related_name='note')
|
baby = models.ForeignKey('Child', related_name='note')
|
||||||
note = models.TextField()
|
note = models.TextField()
|
||||||
time = models.DateTimeField(auto_now=True)
|
time = models.DateTimeField(auto_now=True)
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ class Note(models.Model):
|
||||||
|
|
||||||
|
|
||||||
class Sleep(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)
|
start = models.DateTimeField(blank=False, null=False)
|
||||||
end = 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):
|
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)
|
start = models.DateTimeField(blank=False, null=False)
|
||||||
end = models.DateTimeField(blank=False, null=False)
|
end = models.DateTimeField(blank=False, null=False)
|
||||||
milestone = models.CharField(max_length=255, blank=True)
|
milestone = models.CharField(max_length=255, blank=True)
|
||||||
|
|
|
@ -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 == '/baby/add/' %} active{% endif %}">
|
<li class="nav-item{% if request.path == '/child/add/' %} active{% endif %}">
|
||||||
<a class="nav-link" href="{% url 'baby-add' %}">Add Baby</a>
|
<a class="nav-link" href="{% url 'child-add' %}">Add Child</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<form class="form-inline my-2 my-lg-0">
|
<form class="form-inline my-2 my-lg-0">
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
{% extends 'core/base.html' %}
|
{% extends 'core/base.html' %}
|
||||||
{% load i18n widget_tweaks %}
|
{% load i18n widget_tweaks %}
|
||||||
|
|
||||||
{% block title %}Add a Baby{% endblock %}
|
{% block title %}Add a Child{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>Add a Baby</h1>
|
<h1>Add a Child</h1>
|
||||||
<form role="form" method="post">
|
<form role="form" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{% for field in form %}
|
{% for field in form %}
|
10
core/urls.py
10
core/urls.py
|
@ -7,9 +7,9 @@ from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^$', views.Index.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'child/add/$', views.ChildAdd.as_view(), name='child-add'),
|
||||||
url(r'baby/(?P<pk>[0-9]+)/$', views.BabyUpdate.as_view(),
|
url(r'child/(?P<pk>[0-9]+)/$', views.ChildUpdate.as_view(),
|
||||||
name='baby-update'),
|
name='child-update'),
|
||||||
url(r'baby/(?P<pk>[0-9]+)/delete/$', views.BabyDelete.as_view(),
|
url(r'child/(?P<pk>[0-9]+)/delete/$', views.ChildDelete.as_view(),
|
||||||
name='baby-delete'),
|
name='child-delete'),
|
||||||
]
|
]
|
||||||
|
|
|
@ -4,24 +4,24 @@ 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 .models import Baby
|
from .models import Child
|
||||||
|
|
||||||
|
|
||||||
class Index(TemplateView):
|
class Index(TemplateView):
|
||||||
template_name = 'core/index.html'
|
template_name = 'core/index.html'
|
||||||
|
|
||||||
|
|
||||||
class BabyAdd(CreateView):
|
class ChildAdd(CreateView):
|
||||||
model = Baby
|
model = Child
|
||||||
fields = ['first_name', 'last_name', 'birth_date']
|
fields = ['first_name', 'last_name', 'birth_date']
|
||||||
success_url = '/'
|
success_url = '/'
|
||||||
|
|
||||||
|
|
||||||
class BabyUpdate(UpdateView):
|
class ChildUpdate(UpdateView):
|
||||||
model = Baby
|
model = Child
|
||||||
fields = ['first_name', 'last_name', 'birth_date']
|
fields = ['first_name', 'last_name', 'birth_date']
|
||||||
success_url = '/'
|
success_url = '/'
|
||||||
|
|
||||||
|
|
||||||
class BabyDelete(DeleteView):
|
class ChildDelete(DeleteView):
|
||||||
model = Baby
|
model = Child
|
||||||
|
|
Loading…
Reference in New Issue