Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Add thumbnail images to autocomplete ingredients

Tom Bowyer2f27fc2944ff
diff --git a/.gitignore b/.gitignore
index 595a743c2..9286e0098 100644
--- a/.gitignore
+++ b/.gitignore
@@ -69,3 +69,6 @@ venv-wget
# Dummy file for translations
/wger/i18n.tpl
+
+# Local images folder
+/media
diff --git a/wger/nutrition/api/views.py b/wger/nutrition/api/views.py
index 3be9efbe9..03bcdeccd 100644
--- a/wger/nutrition/api/views.py
+++ b/wger/nutrition/api/views.py
@@ -177,7 +177,7 @@ def search(request):
else:
image = None
thumbnail = None
-
+
ingredient_json = {
'value': ingredient.name,
'data': {
diff --git a/wger/nutrition/templates/ingredient/overview.html b/wger/nutrition/templates/ingredient/overview.html
index 0bc2fd7cb..e9a132343 100644
--- a/wger/nutrition/templates/ingredient/overview.html
+++ b/wger/nutrition/templates/ingredient/overview.html
@@ -20,6 +20,12 @@
minChars: 3,
onSelect: function (suggestion) {
window.location.href = '/nutrition/ingredient/' + suggestion.data.id + '/view/'
+ },
+ formatResult: function (suggestion) {
+ if (suggestion.data.image_thumbnail) {
+ return '<div><img src="' + suggestion.data.image_thumbnail + '" /> ' + suggestion.value + '</div>';
+ }
+ return '<div>' + suggestion.value + '</div>';
}
});
});