Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Remove the fields 'amount_freetext' and 'ingredient_freetext' from MealItem

Roland Geidercbbc09afbd7c
diff --git a/manager/static/js/workout-manager.js b/manager/static/js/workout-manager.js
index d6d04f6ae..92195f958 100644
--- a/manager/static/js/workout-manager.js
+++ b/manager/static/js/workout-manager.js
@@ -208,7 +208,7 @@ function form_modal_dialog()
function init_ingredient_autocompleter()
{
// Init the autocompleter
- $("#id_ingredient_freetext").autocomplete({
+ $("#id_ingredient_searchfield").autocomplete({
source: "/nutrition/ingredient/search/",
minLength: 2,
select: function(event, ui) {
diff --git a/nutrition/models.py b/nutrition/models.py
index f858be0c5..aada5ba86 100644
--- a/nutrition/models.py
+++ b/nutrition/models.py
@@ -110,14 +110,14 @@ class MealItem(models.Model):
blank = True,
validators = [MaxValueValidator(1000)],
verbose_name = _('Amount in gramms'))
- amount_freetext = models.CharField(max_length=30,
- blank = True,
- verbose_name = _('Amount (freetext)'),
- help_text = _('The amount in another unit, e.g. "a spoonfull" or "3 pieces"'))
- ingredient_freetext = models.CharField(max_length=150,
- blank = True,
- verbose_name = _('Ingredient'),
- help_text = _('If the ingredient is not in the system, enter the name here'))
+ #amount_freetext = models.CharField(max_length=30,
+ # blank = True,
+ # verbose_name = _('Amount (freetext)'),
+ # help_text = _('The amount in another unit, e.g. "a spoonfull" or "3 pieces"'))
+ #ingredient_freetext = models.CharField(max_length=150,
+ # blank = True,
+ # verbose_name = _('Ingredient'),
+ # help_text = _('If the ingredient is not in the system, enter the name here'))
ingredient = models.ForeignKey(Ingredient, verbose_name = _('Ingredient'))
def __unicode__(self):
diff --git a/nutrition/templates/edit_meal_item.html b/nutrition/templates/edit_meal_item.html
index c8d11412b..891d092ab 100644
--- a/nutrition/templates/edit_meal_item.html
+++ b/nutrition/templates/edit_meal_item.html
@@ -30,14 +30,24 @@ $(document).ready(function() {
{{ form.non_field_errors }}
<table>
{% include "form_snippet.html" with field=form.amount_gramm %}
- {% include "form_snippet.html" with field=form.amount_freetext %}
{% if js_active %}
<input type="hidden" id="id_ingredient" name="ingredient" value="{{ingredient}}">
- {% include "form_snippet.html" with field=form.ingredient_freetext %}
- {% else %}
+ {% else %}
{% include "form_snippet.html" with field=form.ingredient css_class="ym-fbox-select" %}
{% endif %}
-
+ <tr>
+ <td style="text-align:right;">
+ {% trans "Ingredient name" %}
+ </td>
+ <td>
+ <div class="ym-fbox-text">
+ <input type="text"
+ id="id_ingredient_searchfield"
+ name="ingredient_searchfield"
+ value="{{ingredient_searchfield}}">
+ </div>
+ </td>
+ </tr>
<tr>
<td><input type="submit" value="{% trans "Save" %}" /></td>
<td></td>
diff --git a/nutrition/views.py b/nutrition/views.py
index 54c21dc7b..d2eca5724 100644
--- a/nutrition/views.py
+++ b/nutrition/views.py
@@ -217,7 +217,6 @@ def export_pdf(request, id):
# Manually set the width of the columns
t._argW[0] = 2 * cm
-
# write the document and send the response to the browser
elements.append(t)
@@ -382,6 +381,8 @@ def edit_meal_item(request, id, meal_id, item_id=None):
# so the user can simply submit again.
template_data['ingredient'] = request.POST.get('ingredient', '')
+ template_data['ingredient_searchfield'] = request.POST.get('ingredient_searchfield', '')
+
# If the data is valid, save and redirect
if meal_form.is_valid():