mirror of https://github.com/snachodog/mybuddy.git
Add a Last Diaper Change card.
This commit is contained in:
parent
4cfc6cb360
commit
e92050cb44
|
@ -54,6 +54,16 @@ class DiaperChange(models.Model):
|
||||||
def since(self, time=timezone.now()):
|
def since(self, time=timezone.now()):
|
||||||
return timesince.timesince(self.time, time)
|
return timesince.timesince(self.time, time)
|
||||||
|
|
||||||
|
def attributes(self):
|
||||||
|
attributes = []
|
||||||
|
if self.wet:
|
||||||
|
attributes.append(DiaperChange._meta.get_field('wet').name)
|
||||||
|
if self.solid:
|
||||||
|
attributes.append(DiaperChange._meta.get_field('solid').name)
|
||||||
|
if self.color:
|
||||||
|
attributes.append(self.color)
|
||||||
|
return attributes
|
||||||
|
|
||||||
|
|
||||||
class Feeding(models.Model):
|
class Feeding(models.Model):
|
||||||
child = models.ForeignKey('Child', related_name='feeding')
|
child = models.ForeignKey('Child', related_name='feeding')
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
<div class="card border-danger mb-3">
|
||||||
|
<div class="card-header text-white bg-danger h4">
|
||||||
|
<i class="fa fa-trash pull-left" aria-hidden="true"></i>
|
||||||
|
{% block header %}{% endblock %}
|
||||||
|
</div>
|
||||||
|
<div class="card-body text-danger">
|
||||||
|
<h4 class="card-title">{% block title %}{% endblock %}</h4>
|
||||||
|
<div class="card-text">{% block content %}{% endblock %}</div>
|
||||||
|
</div>
|
||||||
|
<div class="card-footer text-muted">
|
||||||
|
{% block footer %}{% endblock %}
|
||||||
|
</div>
|
||||||
|
</div>
|
|
@ -0,0 +1,15 @@
|
||||||
|
{% extends 'cards/diaperchange.html' %}
|
||||||
|
|
||||||
|
{% block header %}Last Diaper Change{% endblock %}
|
||||||
|
|
||||||
|
{% block title %}
|
||||||
|
<strong>{{ change.time|timesince }}</strong> ago
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="text-muted">
|
||||||
|
{{ change.attributes|join:', ' }}
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block footer %}{{ change.time }}{% endblock %}
|
|
@ -11,7 +11,7 @@
|
||||||
{% card_feeding_last object %}
|
{% card_feeding_last object %}
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-12 col-md-4">
|
<div class="col-sm-12 col-md-4">
|
||||||
last feeding
|
{% card_diaperchange_last object %}
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-12 col-md-4">
|
<div class="col-sm-12 col-md-4">
|
||||||
change statistics
|
change statistics
|
||||||
|
|
|
@ -3,7 +3,7 @@ from __future__ import unicode_literals
|
||||||
|
|
||||||
from django import template
|
from django import template
|
||||||
|
|
||||||
from core.models import Feeding
|
from core.models import DiaperChange, Feeding
|
||||||
|
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
@ -14,3 +14,10 @@ def card_feeding_last(child):
|
||||||
feeding_instance = Feeding.objects.filter(
|
feeding_instance = Feeding.objects.filter(
|
||||||
child=child).order_by('-end').first()
|
child=child).order_by('-end').first()
|
||||||
return {'feeding': feeding_instance}
|
return {'feeding': feeding_instance}
|
||||||
|
|
||||||
|
|
||||||
|
@register.inclusion_tag('cards/diaperchange_last.html')
|
||||||
|
def card_diaperchange_last(child):
|
||||||
|
feeding_instance = DiaperChange.objects.filter(
|
||||||
|
child=child).order_by('-time').first()
|
||||||
|
return {'change': feeding_instance}
|
||||||
|
|
Loading…
Reference in New Issue