mirror of https://github.com/snachodog/mybuddy.git
Add DiaperChange model.
This commit is contained in:
parent
f5d91affcf
commit
105adec971
|
@ -4,7 +4,7 @@ from __future__ import unicode_literals
|
|||
from django.contrib.auth.models import User
|
||||
from rest_framework import serializers
|
||||
|
||||
from core.models import Baby, Feeding, Sleep, TummyTime
|
||||
from core.models import Baby, DiaperChange, Feeding, Sleep, TummyTime
|
||||
|
||||
|
||||
class BabySerializer(serializers.HyperlinkedModelSerializer):
|
||||
|
@ -13,6 +13,12 @@ class BabySerializer(serializers.HyperlinkedModelSerializer):
|
|||
fields = ('first_name', 'last_name', 'birth_date')
|
||||
|
||||
|
||||
class DiaperChangeSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = DiaperChange
|
||||
fields = ('baby', 'time', 'wet', 'solid', 'color')
|
||||
|
||||
|
||||
class FeedingSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = Feeding
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
from django.conf.urls import url, include
|
||||
from rest_framework import routers
|
||||
|
||||
from .views import (BabyViewSet, FeedingViewSet, SleepViewSet, TummyTimeViewSet,
|
||||
UserViewSet)
|
||||
from .views import (BabyViewSet, DiaperChangeViewSet, FeedingViewSet,
|
||||
SleepViewSet, TummyTimeViewSet, UserViewSet)
|
||||
|
||||
# Routers provide an easy way of automatically determining the URL conf.
|
||||
router = routers.DefaultRouter()
|
||||
router.register(r'babies', BabyViewSet)
|
||||
router.register(r'diaper-changes', DiaperChangeViewSet)
|
||||
router.register(r'feedings', FeedingViewSet)
|
||||
router.register(r'sleep', SleepViewSet)
|
||||
router.register(r'sleep', SleepViewSet)
|
||||
router.register(r'tummy-times', TummyTimeViewSet)
|
||||
router.register(r'users', UserViewSet)
|
||||
|
||||
# Wire up our API using automatic URL routing.
|
||||
|
|
10
api/views.py
10
api/views.py
|
@ -4,8 +4,9 @@ from __future__ import unicode_literals
|
|||
from django.contrib.auth.models import User
|
||||
from rest_framework import viewsets
|
||||
|
||||
from core.models import Baby, Feeding, Sleep, TummyTime
|
||||
from .serializers import (BabySerializer, FeedingSerializer, SleepSerializer,
|
||||
from core.models import Baby, DiaperChange, Feeding, Sleep, TummyTime
|
||||
from .serializers import (BabySerializer, DiaperChangeSerializer,
|
||||
FeedingSerializer, SleepSerializer,
|
||||
TummyTimeSerializer, UserSerializer,)
|
||||
|
||||
|
||||
|
@ -14,6 +15,11 @@ class BabyViewSet(viewsets.ModelViewSet):
|
|||
serializer_class = BabySerializer
|
||||
|
||||
|
||||
class DiaperChangeViewSet(viewsets.ModelViewSet):
|
||||
queryset = DiaperChange.objects.all()
|
||||
serializer_class = DiaperChangeSerializer
|
||||
|
||||
|
||||
class FeedingViewSet(viewsets.ModelViewSet):
|
||||
queryset = Feeding.objects.all()
|
||||
serializer_class = FeedingSerializer
|
||||
|
|
|
@ -3,7 +3,7 @@ from __future__ import unicode_literals
|
|||
|
||||
from django.contrib import admin
|
||||
|
||||
from .models import Baby, Feeding, Sleep, TummyTime
|
||||
from .models import Baby, DiaperChange, Feeding, Sleep, TummyTime
|
||||
|
||||
|
||||
@admin.register(Baby)
|
||||
|
@ -12,6 +12,12 @@ class BabyAdmin(admin.ModelAdmin):
|
|||
search_fields = ('first_name', 'last_name', 'birth_date',)
|
||||
|
||||
|
||||
@admin.register(DiaperChange)
|
||||
class DiaperChangeAdmin(admin.ModelAdmin):
|
||||
list_display = ('baby', 'time', 'wet', 'solid', 'color')
|
||||
search_fields = ('baby__first_name', 'baby__last_name',)
|
||||
|
||||
|
||||
@admin.register(Feeding)
|
||||
class FeedingAdmin(admin.ModelAdmin):
|
||||
list_display = ('start', 'end', 'duration', 'baby', 'type', 'method',)
|
||||
|
|
|
@ -22,6 +22,28 @@ class Baby(models.Model):
|
|||
return '{} {}'.format(self.first_name, self.last_name)
|
||||
|
||||
|
||||
class DiaperChange(models.Model):
|
||||
baby = models.ForeignKey('Baby', related_name='diaper_change')
|
||||
time = models.DateTimeField(blank=False, null=False)
|
||||
wet = models.BooleanField()
|
||||
solid = models.BooleanField()
|
||||
color = models.CharField(max_length=255, blank=True, choices=[
|
||||
('black', 'Black'),
|
||||
('brown', 'Brown'),
|
||||
('green', 'Green'),
|
||||
('yellow', 'Yellow'),
|
||||
])
|
||||
|
||||
objects = models.Manager()
|
||||
|
||||
class Meta:
|
||||
default_permissions = ('view', 'add', 'change', 'delete')
|
||||
ordering = ['-time']
|
||||
|
||||
def __str__(self):
|
||||
return 'Diaper change for {} on {}'.format(self.baby, self.time.date())
|
||||
|
||||
|
||||
class Feeding(models.Model):
|
||||
baby = models.ForeignKey('Baby', related_name='feeding')
|
||||
start = models.DateTimeField(blank=False, null=False)
|
||||
|
|
Loading…
Reference in New Issue