Self hosted FLOSS fitness/workout, nutrition and weight tracker
Crispify meal item forms
Roland Geider03e605aa2b8e
diff --git a/wger/nutrition/forms.py b/wger/nutrition/forms.pyindex f7deea6af..992ef004c 100644--- a/wger/nutrition/forms.py+++ b/wger/nutrition/forms.py@@ -28,6 +28,7 @@ from django.utils.translation import (from crispy_forms.helper import FormHelperfrom crispy_forms.layout import (Column,+ HTML,Layout,Row)@@ -152,9 +153,13 @@ class MealItemForm(forms.ModelForm):ingredient = forms.ModelChoiceField(queryset=Ingredient.objects.all(),widget=forms.HiddenInput)+ ingredient_searchfield = forms.CharField()+class Meta:model = MealItem- fields = '__all__'+ fields = ['ingredient',+ 'weight_unit',+ 'amount']def __init__(self, *args, **kwargs):super(MealItemForm, self).__init__(*args, **kwargs)@@ -172,3 +177,15 @@ class MealItemForm(forms.ModelForm):if ingredient_id:self.fields['weight_unit'].queryset = \IngredientWeightUnit.objects.filter(ingredient_id=ingredient_id)++ self.helper = FormHelper()+ self.helper.layout = Layout(+ 'ingredient',+ 'ingredient_searchfield',+ HTML('<div id="exercise_name"></div>'),+ Row(+ Column('amount', css_class='form-group col-6 mb-0'),+ Column('weight_unit', css_class='form-group col-6 mb-0'),+ css_class='form-row'+ )+ )diff --git a/wger/nutrition/templates/meal_item/edit.html b/wger/nutrition/templates/meal_item/edit.htmldeleted file mode 100644index df621d094..000000000--- a/wger/nutrition/templates/meal_item/edit.html+++ /dev/null@@ -1,48 +0,0 @@-{% extends "base.html" %}-{% load i18n %}-{% load static %}-{% load wger_extras %}---{% block title %}{% trans "Edit meal item" %}{% endblock %}---{% block header %}-<script type="text/javascript">-$(document).ready(function() {- // Init the autocompleter- wgerInitIngredientAutocompleter();-});-</script>-{% endblock %}-----{% block content %}-<form action="{{ form_action }}"- method="post"- class="wger-form">- {% csrf_token %}- {% render_form_errors form %}- {{form.ingredient}}-- <div class="form-group {% if field.errors %}has-error{% endif %}" id="form-id_ingredient_searchfield">- <label for="id_ingredient_searchfield" class="col-md-3 control-label">- {% trans "Ingredient name" %}- </label>-- <div class="col-md-9">- <input type="text"- id="id_ingredient_searchfield"- name="ingredient_searchfield"- value="{{ingredient_searchfield}}"- class="form-control">- <div id="exercise_name"></div>- </div>- </div>- {% render_form_field form.amount %}- {% render_form_field form.weight_unit %}- {% render_form_submit submit_text %}-</form>-{% endblock %}diff --git a/wger/nutrition/views/meal_item.py b/wger/nutrition/views/meal_item.pyindex 3b6f36a47..1f2630a65 100644--- a/wger/nutrition/views/meal_item.py+++ b/wger/nutrition/views/meal_item.py@@ -68,7 +68,7 @@ class MealItemCreateView(WgerFormMixin, CreateView):model = MealItemform_class = MealItemForm- template_name = 'meal_item/edit.html'+ custom_js = 'wgerInitIngredientAutocompleter();'def dispatch(self, request, *args, **kwargs):"""@@ -108,8 +108,8 @@ class MealItemEditView(WgerFormMixin, UpdateView):model = MealItemform_class = MealItemForm+ custom_js = 'wgerInitIngredientAutocompleter();'title = ugettext_lazy('Edit meal item')- template_name = 'meal_item/edit.html'def get_success_url(self):return reverse('nutrition:plan:view', kwargs={'id': self.object.meal.plan.id})