Add notes to child timeline

This commit is contained in:
Marcelino Alberdi Pereira 2021-11-20 18:41:15 +01:00 committed by Christopher Charbonneau Wells
parent 2fea4c8806
commit 462459964c
1 changed files with 17 additions and 1 deletions

View File

@ -3,7 +3,7 @@ from django.urls import reverse
from django.utils import timezone, timesince from django.utils import timezone, timesince
from django.utils.translation import gettext as _ from django.utils.translation import gettext as _
from core.models import DiaperChange, Feeding, Sleep, TummyTime from core.models import DiaperChange, Feeding, Note, Sleep, TummyTime
from datetime import timedelta from datetime import timedelta
@ -22,6 +22,7 @@ def get_objects(date, child=None):
_add_feedings(min_date, max_date, events, child) _add_feedings(min_date, max_date, events, child)
_add_sleeps(min_date, max_date, events, child) _add_sleeps(min_date, max_date, events, child)
_add_tummy_times(min_date, max_date, events, child) _add_tummy_times(min_date, max_date, events, child)
_add_notes(min_date, max_date, events, child)
events.sort(key=lambda x: x['time'], reverse=True) events.sort(key=lambda x: x['time'], reverse=True)
@ -169,3 +170,18 @@ def _add_diaper_changes(min_date, max_date, events, child):
args=[instance.id]), args=[instance.id]),
'model_name': instance.model_name 'model_name': instance.model_name
}) })
def _add_notes(min_date, max_date, events, child):
instances = Note.objects.filter(
time__range=(min_date, max_date)).order_by('-time')
if child:
instances = instances.filter(child=child)
for instance in instances:
events.append({
'time': timezone.localtime(instance.time),
'details': [instance.note],
'edit_link': reverse('core:note-update',
args=[instance.id]),
'model_name': instance.model_name
})