Skip to content

Commit

Permalink
Add notes to child timeline
Browse files Browse the repository at this point in the history
  • Loading branch information
Alberdi authored and cdubz committed Nov 20, 2021
1 parent 2fea4c8 commit 4624599
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion core/timeline.py
Expand Up @@ -3,7 +3,7 @@
from django.utils import timezone, timesince
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


Expand All @@ -22,6 +22,7 @@ def get_objects(date, child=None):
_add_feedings(min_date, max_date, events, child)
_add_sleeps(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)

Expand Down Expand Up @@ -169,3 +170,18 @@ def _add_diaper_changes(min_date, max_date, events, child):
args=[instance.id]),
'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
})

0 comments on commit 4624599

Please sign in to comment.