mirror of https://github.com/snachodog/mybuddy.git
Obscure timer-child relations for one child use case
This commit is contained in:
parent
6662d1036d
commit
e5a5e330b9
|
@ -251,7 +251,7 @@ class Feeding(models.Model):
|
||||||
validate_unique_period(Feeding.objects.filter(child=self.child), self)
|
validate_unique_period(Feeding.objects.filter(child=self.child), self)
|
||||||
|
|
||||||
# "Formula" Type may only be associated with "Bottle" Method.
|
# "Formula" Type may only be associated with "Bottle" Method.
|
||||||
if self.type == 'formula'and self.method != 'bottle':
|
if self.type == 'formula' and self.method != 'bottle':
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
{'method':
|
{'method':
|
||||||
_('Only "Bottle" method is allowed with "Formula" type.')},
|
_('Only "Bottle" method is allowed with "Formula" type.')},
|
||||||
|
@ -435,8 +435,13 @@ class Timer(models.Model):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def title_with_child(self):
|
def title_with_child(self):
|
||||||
return format_lazy('{title} ({child})', title=str(self),
|
""" Get Timer title with child name in parenthesis. """
|
||||||
child=self.child)
|
title = str(self)
|
||||||
|
# Only actually add the name if there is more than one Child instance.
|
||||||
|
if title and self.child and Child.count() > 1:
|
||||||
|
title = format_lazy('{title} ({child})', title=title,
|
||||||
|
child=self.child)
|
||||||
|
return title
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_db(cls, db, field_names, values):
|
def from_db(cls, db, field_names, values):
|
||||||
|
|
|
@ -27,7 +27,13 @@
|
||||||
{% for timer in object_list %}
|
{% for timer in object_list %}
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row"><a href="{% url 'core:timer-detail' timer.id %}">{{ timer }}</a></th>
|
<th scope="row"><a href="{% url 'core:timer-detail' timer.id %}">{{ timer }}</a></th>
|
||||||
<td><a href="{% url 'core:child' timer.child.slug %}">{{ timer.child }}</a></td>
|
<td>
|
||||||
|
{% if timer.child %}
|
||||||
|
<a href="{% url 'core:child' timer.child.slug %}">{{ timer.child }}</a>
|
||||||
|
{% else %}
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
<td>{{ timer.start }}</td>
|
<td>{{ timer.start }}</td>
|
||||||
<td>{{ timer.duration|duration_string }}</td>
|
<td>{{ timer.duration|duration_string }}</td>
|
||||||
<td>{{ timer.end }}</td>
|
<td>{{ timer.end }}</td>
|
||||||
|
|
|
@ -297,6 +297,9 @@ class TimerAddQuick(PermissionRequired403Mixin, RedirectView):
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
instance = models.Timer.objects.create(user=request.user)
|
instance = models.Timer.objects.create(user=request.user)
|
||||||
|
# Add child relationship if there is only Child instance.
|
||||||
|
if models.Child.count() == 1:
|
||||||
|
instance.child = models.Child.objects.first()
|
||||||
instance.save()
|
instance.save()
|
||||||
self.url = request.GET.get(
|
self.url = request.GET.get(
|
||||||
'next', reverse('core:timer-detail', args={instance.id}))
|
'next', reverse('core:timer-detail', args={instance.id}))
|
||||||
|
|
Loading…
Reference in New Issue