mirror of https://github.com/snachodog/mybuddy.git
⚗️ changes the way to select child in feeding (for now)
- uses input radio instead of select, - displays child thumbnail.
This commit is contained in:
parent
3a022f8b12
commit
424f9947af
|
@ -8,7 +8,7 @@ from django.utils.translation import gettext as _
|
||||||
from taggit.forms import TagField
|
from taggit.forms import TagField
|
||||||
|
|
||||||
from core import models
|
from core import models
|
||||||
from core.widgets import TagsEditor
|
from core.widgets import TagsEditor, ChildRadioSelect
|
||||||
|
|
||||||
|
|
||||||
def set_initial_values(kwargs, form_type):
|
def set_initial_values(kwargs, form_type):
|
||||||
|
@ -173,6 +173,7 @@ class FeedingForm(CoreModelForm, TaggableModelForm):
|
||||||
model = models.Feeding
|
model = models.Feeding
|
||||||
fields = ["child", "start", "end", "type", "method", "amount", "notes", "tags"]
|
fields = ["child", "start", "end", "type", "method", "amount", "notes", "tags"]
|
||||||
widgets = {
|
widgets = {
|
||||||
|
"child": ChildRadioSelect,
|
||||||
"start": forms.DateTimeInput(
|
"start": forms.DateTimeInput(
|
||||||
attrs={
|
attrs={
|
||||||
"autocomplete": "off",
|
"autocomplete": "off",
|
||||||
|
|
|
@ -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 %}
|
|
@ -1,6 +1,6 @@
|
||||||
from django.forms import Media
|
|
||||||
from typing import Any, Dict, Optional
|
from typing import Any, Dict, Optional
|
||||||
from django.forms import Widget
|
|
||||||
|
from django.forms import Widget, RadioSelect
|
||||||
|
|
||||||
from . import models
|
from . import models
|
||||||
|
|
||||||
|
@ -81,3 +81,13 @@ class TagsEditor(Widget):
|
||||||
"most": [self.__unpack_tag(t) for t in most_tags],
|
"most": [self.__unpack_tag(t) for t in most_tags],
|
||||||
}
|
}
|
||||||
return result
|
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
|
||||||
|
|
Loading…
Reference in New Issue