update food after changing category

This commit is contained in:
vabene1111
2021-01-26 18:08:41 +01:00
parent 26ec1724a5
commit 15c758b24a
2 changed files with 24 additions and 19 deletions

View File

@ -173,7 +173,7 @@ class SupermarketSerializer(UniqueFieldsMixin, serializers.ModelSerializer):
class FoodSerializer(UniqueFieldsMixin, WritableNestedModelSerializer): class FoodSerializer(UniqueFieldsMixin, WritableNestedModelSerializer):
supermarket_category = SupermarketCategorySerializer(allow_null=True) supermarket_category = SupermarketCategorySerializer(allow_null=True, required=False)
def create(self, validated_data): def create(self, validated_data):
# since multi select tags dont have id's # since multi select tags dont have id's

View File

@ -568,7 +568,8 @@
"shared": [{% for u in request.user.userpreference.plan_share.all %} "shared": [{% for u in request.user.userpreference.plan_share.all %}
{'id': {{ u.pk }}, 'username': '{{ u.get_user_name }}'}, {'id': {{ u.pk }}, 'username': '{{ u.get_user_name }}'},
{% endfor %}], {% endfor %}],
"created_by": 1 "created_by": {{ request.user.pk }},
"supermarket": null
} }
this.loading = false this.loading = false
@ -638,7 +639,9 @@
}, },
dragChanged: function (category, evt) { dragChanged: function (category, evt) {
if (evt.added !== undefined) { if (evt.added !== undefined) {
console.log('element was added to new list', category, evt) if (evt.added.element.id === undefined) {
this.makeToast(gettext('Warning'), gettext('This feature is only available after saving the shopping list'), 'warning')
} else {
this.shopping_list.entries.forEach(entry => { this.shopping_list.entries.forEach(entry => {
if (entry.id === evt.added.element.id) { if (entry.id === evt.added.element.id) {
if (category.id === -1) { if (category.id === -1) {
@ -649,7 +652,6 @@
id: category.id id: category.id
} }
} }
console.log('UPDATING FOOD OBJECT', entry.food)
this.$http.put(("{% url 'api:food-detail' 123456 %}").replace('123456', entry.food.id), entry.food).then((response) => { this.$http.put(("{% url 'api:food-detail' 123456 %}").replace('123456', entry.food.id), entry.food).then((response) => {
}).catch((err) => { }).catch((err) => {
@ -658,6 +660,9 @@
} }
}) })
} }
}
}, },
entryChecked: function (entry) { entryChecked: function (entry) {
this.shopping_list.entries.forEach((item) => { this.shopping_list.entries.forEach((item) => {