⚗️ changes the way to select child in feeding (for now)

- uses input radio instead of select,
- displays child thumbnail.
This commit is contained in:
Jean-Louis Jouannic 2022-07-02 16:49:21 +02:00 committed by Christopher Charbonneau Wells
parent 3a022f8b12
commit 424f9947af
3 changed files with 26 additions and 3 deletions

View File

@ -8,7 +8,7 @@ from django.utils.translation import gettext as _
from taggit.forms import TagField
from core import models
from core.widgets import TagsEditor
from core.widgets import TagsEditor, ChildRadioSelect
def set_initial_values(kwargs, form_type):
@ -173,6 +173,7 @@ class FeedingForm(CoreModelForm, TaggableModelForm):
model = models.Feeding
fields = ["child", "start", "end", "type", "method", "amount", "notes", "tags"]
widgets = {
"child": ChildRadioSelect,
"start": forms.DateTimeInput(
attrs={
"autocomplete": "off",

View File

@ -0,0 +1,12 @@
{% load imagekit static %}
{% if widget.wrap_label %}
<label{% if widget.attrs.id %}
for="{{ widget.attrs.id }}"{% endif %}>{% endif %}{% include "django/forms/widgets/input.html" %}
{% if widget.wrap_label %}{% if widget.picture %}
{% thumbnail '40x40' widget.picture as thumb %}
<img src="{{ thumb.url }}" class="img-fluid rounded-circle" />
{% else %}
<img src="{% static 'babybuddy/img/core/child-placeholder.png' %}"
width="40" height="40" class="img-fluid rounded-circle" />
{% endif %} {{ widget.label }}</label>{% endif %}

View File

@ -1,6 +1,6 @@
from django.forms import Media
from typing import Any, Dict, Optional
from django.forms import Widget
from django.forms import Widget, RadioSelect
from . import models
@ -81,3 +81,13 @@ class TagsEditor(Widget):
"most": [self.__unpack_tag(t) for t in most_tags],
}
return result
class ChildRadioSelect(RadioSelect):
input_type = "radio"
option_template_name = "core/child_radio_option.html"
def create_option(self, name, value, label, selected, index, subindex=None, attrs=None):
option = super().create_option(name, value, label, selected, index, subindex, attrs)
option['picture'] = value.instance.picture
return option