feat: create a trimmed form just for bottle feeding.

While Feeding for is great, i think there is room to create optimised
forms for breast feeding and bottle feeding.

This is the first one a trimmed down form for bottle feeding
specifically
This commit is contained in:
billybonksl 2024-01-26 17:28:24 +08:00 committed by Christopher Charbonneau Wells
parent 4ff6f7dd9b
commit 3c54636790
5 changed files with 40 additions and 1 deletions

View File

@ -264,7 +264,12 @@
{% trans "Feeding" %}
</a>
{% endif %}
{% if perms.core.add_feeding %}
<a class="dropdown-item ps-5{% if request.path == '/feedings/bottle/add/' %} active{% endif %}"
href="{% url 'core:bottle-feeding-add' %}"><i class="icon-add" aria-hidden="true"></i>
{% trans "Bottle Feeding" %}
</a>
{% endif %}
{% if perms.core.view_pumping %}
<a class="dropdown-item{% if request.path == '/pumping/' %} active{% endif %}"
href="{% url 'core:pumping-list' %}">

View File

@ -187,6 +187,24 @@ class FeedingForm(CoreModelForm, TaggableModelForm):
}
class BottleFeedingForm(CoreModelForm, TaggableModelForm):
def save(self):
instance = super(BottleFeedingForm, self).save(commit=False)
instance.method = "bottle"
instance.end = instance.start
instance.save()
return instance
class Meta:
model = models.Feeding
fields = ["child", "start", "type", "amount", "notes", "tags"]
widgets = {
"child": ChildRadioSelect,
"start": DateTimeInput(),
"notes": forms.Textarea(attrs={"rows": 5}),
}
class NoteForm(CoreModelForm, TaggableModelForm):
class Meta:
model = models.Note

View File

@ -4,6 +4,8 @@
{% block title %}
{% if request.resolver_match.url_name == 'feeding-update' %}
{% trans "Update a Feeding" %}
{% elif request.resolver_match.url_name == 'bottle-feeding-add' %}
{% trans "Add a Bottle Feeding" %}
{% else %}
{% trans "Add a Feeding" %}
{% endif %}
@ -23,6 +25,8 @@
{% blocktrans trimmed %}
<h1>Update <span class="text-info">{{ object }}</span></h1>
{% endblocktrans %}
{% elif request.resolver_match.url_name == 'bottle-feeding-add' %}
<h1>{% trans "Add a Bottle Feeding" %}</h1>
{% else %}
<h1>{% trans "Add a Feeding" %}</h1>
{% endif %}

View File

@ -38,6 +38,11 @@ urlpatterns = [
views.DiaperChangeDelete.as_view(),
name="diaperchange-delete",
),
path(
"feedings/bottle/add/",
views.BottleFeedingAdd.as_view(),
name="bottle-feeding-add",
),
path("feedings/", views.FeedingList.as_view(), name="feeding-list"),
path("feedings/add/", views.FeedingAdd.as_view(), name="feeding-add"),
path("feedings/<int:pk>/", views.FeedingUpdate.as_view(), name="feeding-update"),

View File

@ -192,6 +192,13 @@ class FeedingAdd(CoreAddView):
success_url = reverse_lazy("core:feeding-list")
class BottleFeedingAdd(CoreAddView):
model = models.Feeding
permission_required = ("core.add_feeding",)
form_class = forms.BottleFeedingForm
success_url = reverse_lazy("core:feeding-list")
class FeedingUpdate(CoreUpdateView):
model = models.Feeding
permission_required = ("core.change_feeding",)