mirror of https://github.com/snachodog/mybuddy.git
Add a generic Note model.
This commit is contained in:
parent
a234799418
commit
99c6e54cc2
|
@ -3,7 +3,7 @@ from __future__ import unicode_literals
|
|||
|
||||
from rest_framework import serializers
|
||||
|
||||
from core.models import Baby, DiaperChange, Feeding, Sleep, TummyTime
|
||||
from core.models import Baby, DiaperChange, Feeding, Note, Sleep, TummyTime
|
||||
|
||||
|
||||
class BabySerializer(serializers.HyperlinkedModelSerializer):
|
||||
|
@ -24,6 +24,12 @@ class FeedingSerializer(serializers.HyperlinkedModelSerializer):
|
|||
fields = ('baby', 'start', 'end', 'duration', 'type', 'method')
|
||||
|
||||
|
||||
class NoteSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = Note
|
||||
fields = ('baby', 'note', 'time')
|
||||
|
||||
|
||||
class SleepSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = Sleep
|
||||
|
|
|
@ -2,12 +2,13 @@ from django.conf.urls import url, include
|
|||
from rest_framework import routers
|
||||
|
||||
from .views import (BabyViewSet, DiaperChangeViewSet, FeedingViewSet,
|
||||
SleepViewSet, TummyTimeViewSet)
|
||||
NoteViewSet, SleepViewSet, TummyTimeViewSet)
|
||||
|
||||
router = routers.DefaultRouter()
|
||||
router.register(r'babies', BabyViewSet)
|
||||
router.register(r'diaper-changes', DiaperChangeViewSet)
|
||||
router.register(r'feedings', FeedingViewSet)
|
||||
router.register(r'notes', NoteViewSet)
|
||||
router.register(r'sleep', SleepViewSet)
|
||||
router.register(r'tummy-times', TummyTimeViewSet)
|
||||
|
||||
|
|
13
api/views.py
13
api/views.py
|
@ -3,10 +3,10 @@ from __future__ import unicode_literals
|
|||
|
||||
from rest_framework import viewsets
|
||||
|
||||
from core.models import Baby, DiaperChange, Feeding, Sleep, TummyTime
|
||||
from core.models import Baby, DiaperChange, Feeding, Note, Sleep, TummyTime
|
||||
from core.utils import filter_by_params
|
||||
from .serializers import (BabySerializer, DiaperChangeSerializer,
|
||||
FeedingSerializer, SleepSerializer,
|
||||
FeedingSerializer, NoteSerializer, SleepSerializer,
|
||||
TummyTimeSerializer,)
|
||||
|
||||
|
||||
|
@ -37,6 +37,15 @@ class FeedingViewSet(viewsets.ModelViewSet):
|
|||
return filter_by_params(self.request, Feeding, params)
|
||||
|
||||
|
||||
class NoteViewSet(viewsets.ModelViewSet):
|
||||
queryset = Note.objects.all()
|
||||
serializer_class = NoteSerializer
|
||||
|
||||
def get_queryset(self):
|
||||
params = ['baby__last_name']
|
||||
return filter_by_params(self.request, Note, params)
|
||||
|
||||
|
||||
class SleepViewSet(viewsets.ModelViewSet):
|
||||
queryset = Sleep.objects.all()
|
||||
serializer_class = SleepSerializer
|
||||
|
|
|
@ -3,7 +3,7 @@ from __future__ import unicode_literals
|
|||
|
||||
from django.contrib import admin
|
||||
|
||||
from .models import Baby, DiaperChange, Feeding, Sleep, TummyTime
|
||||
from .models import Baby, DiaperChange, Feeding, Note, Sleep, TummyTime
|
||||
|
||||
|
||||
@admin.register(Baby)
|
||||
|
@ -27,6 +27,13 @@ class FeedingAdmin(admin.ModelAdmin):
|
|||
search_fields = ('baby__first_name', 'baby__last_name', 'type', 'method',)
|
||||
|
||||
|
||||
@admin.register(Note)
|
||||
class NoteAdmin(admin.ModelAdmin):
|
||||
list_display = ('time', 'baby', 'note',)
|
||||
list_filter = ('baby',)
|
||||
search_fields = ('baby__last_name',)
|
||||
|
||||
|
||||
@admin.register(Sleep)
|
||||
class SleepAdmin(admin.ModelAdmin):
|
||||
list_display = ('start', 'end', 'duration', 'baby',)
|
||||
|
|
|
@ -72,6 +72,21 @@ class Feeding(models.Model):
|
|||
return duration_string(self.start, self.end)
|
||||
|
||||
|
||||
class Note(models.Model):
|
||||
baby = models.ForeignKey('Baby', related_name='note')
|
||||
note = models.TextField()
|
||||
time = models.DateTimeField(auto_now=True)
|
||||
|
||||
objects = models.Manager()
|
||||
|
||||
class Meta:
|
||||
default_permissions = ('view', 'add', 'change', 'delete')
|
||||
ordering = ['-time']
|
||||
|
||||
def __str__(self):
|
||||
return 'Note about {} on {}'.format(self.baby, self.time.date())
|
||||
|
||||
|
||||
class Sleep(models.Model):
|
||||
baby = models.ForeignKey('Baby', related_name='sleep')
|
||||
start = models.DateTimeField(blank=False, null=False)
|
||||
|
|
Loading…
Reference in New Issue