inheritance works with object moves
This commit is contained in:
parent
fbe748db62
commit
2a138a852f
@ -15,6 +15,7 @@ from django.core.files.uploadedfile import InMemoryUploadedFile, UploadedFile
|
|||||||
from django.core.validators import MinLengthValidator
|
from django.core.validators import MinLengthValidator
|
||||||
from django.db import IntegrityError, models
|
from django.db import IntegrityError, models
|
||||||
from django.db.models import Index, ProtectedError, Q, Subquery
|
from django.db.models import Index, ProtectedError, Q, Subquery
|
||||||
|
from django.db.models.fields.related import ManyToManyField
|
||||||
from django.db.models.functions import Substr
|
from django.db.models.functions import Substr
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
|
@ -130,12 +130,19 @@ class UserNameSerializer(WritableNestedModelSerializer):
|
|||||||
fields = ('id', 'username')
|
fields = ('id', 'username')
|
||||||
|
|
||||||
|
|
||||||
class FoodInheritFieldSerializer(UniqueFieldsMixin, serializers.ModelSerializer):
|
class FoodInheritFieldSerializer(UniqueFieldsMixin):
|
||||||
|
|
||||||
|
def create(self, validated_data):
|
||||||
|
# don't allow writing to FoodInheritField via API
|
||||||
|
return FoodInheritField.objects.get(**validated_data)
|
||||||
|
|
||||||
|
def update(self, instance, validated_data):
|
||||||
|
# don't allow writing to FoodInheritField via API
|
||||||
|
return FoodInheritField.objects.get(**validated_data)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = FoodInheritField
|
model = FoodInheritField
|
||||||
fields = ['id', 'name', 'field', ]
|
fields = ['id', 'name', 'field', ]
|
||||||
read_only_fields = ('id', 'name', 'field', )
|
|
||||||
|
|
||||||
|
|
||||||
class UserPreferenceSerializer(serializers.ModelSerializer):
|
class UserPreferenceSerializer(serializers.ModelSerializer):
|
||||||
@ -266,18 +273,6 @@ class KeywordSerializer(UniqueFieldsMixin, ExtendedRecipeMixin):
|
|||||||
def get_label(self, obj):
|
def get_label(self, obj):
|
||||||
return str(obj)
|
return str(obj)
|
||||||
|
|
||||||
# def get_image(self, obj):
|
|
||||||
# recipes = obj.recipe_set.all().filter(space=obj.space).exclude(image__isnull=True).exclude(image__exact='')
|
|
||||||
# if recipes.count() == 0 and obj.has_children():
|
|
||||||
# recipes = Recipe.objects.filter(keywords__in=obj.get_descendants(), space=obj.space).exclude(image__isnull=True).exclude(image__exact='') # if no recipes found - check whole tree
|
|
||||||
# if recipes.count() != 0:
|
|
||||||
# return random.choice(recipes).image.url
|
|
||||||
# else:
|
|
||||||
# return None
|
|
||||||
|
|
||||||
# def count_recipes(self, obj):
|
|
||||||
# return obj.recipe_set.filter(space=self.context['request'].space).all().count()
|
|
||||||
|
|
||||||
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
|
||||||
# duplicate names might be routed to create
|
# duplicate names might be routed to create
|
||||||
@ -361,7 +356,7 @@ class FoodSerializer(UniqueFieldsMixin, WritableNestedModelSerializer, ExtendedR
|
|||||||
supermarket_category = SupermarketCategorySerializer(allow_null=True, required=False)
|
supermarket_category = SupermarketCategorySerializer(allow_null=True, required=False)
|
||||||
recipe = RecipeSimpleSerializer(allow_null=True, required=False)
|
recipe = RecipeSimpleSerializer(allow_null=True, required=False)
|
||||||
shopping = serializers.SerializerMethodField('get_shopping_status')
|
shopping = serializers.SerializerMethodField('get_shopping_status')
|
||||||
ignore_inherit = FoodInheritFieldSerializer(allow_null=True, required=False, many=True)
|
ignore_inherit = FoodInheritFieldSerializer(many=True)
|
||||||
|
|
||||||
recipe_filter = 'steps__ingredients__food'
|
recipe_filter = 'steps__ingredients__food'
|
||||||
|
|
||||||
|
@ -48,6 +48,7 @@ def update_step_search_vector(sender, instance=None, created=False, **kwargs):
|
|||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=Food)
|
@receiver(post_save, sender=Food)
|
||||||
|
@skip_signal
|
||||||
def update_food_inheritance(sender, instance=None, created=False, **kwargs):
|
def update_food_inheritance(sender, instance=None, created=False, **kwargs):
|
||||||
if not instance:
|
if not instance:
|
||||||
return
|
return
|
||||||
|
@ -64,7 +64,7 @@ import { BootstrapVue } from "bootstrap-vue"
|
|||||||
|
|
||||||
import "bootstrap-vue/dist/bootstrap-vue.css"
|
import "bootstrap-vue/dist/bootstrap-vue.css"
|
||||||
|
|
||||||
import { CardMixin, ApiMixin, getConfig, StandardToasts, getUserPreference } from "@/utils/utils"
|
import { CardMixin, ApiMixin, getConfig, StandardToasts, getUserPreference, makeToast } from "@/utils/utils"
|
||||||
|
|
||||||
import GenericInfiniteCards from "@/components/GenericInfiniteCards"
|
import GenericInfiniteCards from "@/components/GenericInfiniteCards"
|
||||||
import GenericHorizontalCard from "@/components/GenericHorizontalCard"
|
import GenericHorizontalCard from "@/components/GenericHorizontalCard"
|
||||||
@ -296,11 +296,11 @@ export default {
|
|||||||
.then((result) => {
|
.then((result) => {
|
||||||
this.moveUpdateItem(source_id, target_id)
|
this.moveUpdateItem(source_id, target_id)
|
||||||
// TODO make standard toast
|
// TODO make standard toast
|
||||||
this.makeToast(this.$t("Success"), "Succesfully moved resource", "success")
|
makeToast(this.$t("Success"), "Succesfully moved resource", "success")
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.log(err)
|
console.log(err)
|
||||||
this.makeToast(this.$t("Error"), err.bodyText, "danger")
|
makeToast(this.$t("Error"), err.bodyText, "danger")
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
moveUpdateItem: function (source_id, target_id) {
|
moveUpdateItem: function (source_id, target_id) {
|
||||||
@ -336,12 +336,12 @@ export default {
|
|||||||
.then((result) => {
|
.then((result) => {
|
||||||
this.mergeUpdateItem(source_id, target_id)
|
this.mergeUpdateItem(source_id, target_id)
|
||||||
// TODO make standard toast
|
// TODO make standard toast
|
||||||
this.makeToast(this.$t("Success"), "Succesfully merged resource", "success")
|
makeToast(this.$t("Success"), "Succesfully merged resource", "success")
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
//TODO error checking not working with OpenAPI methods
|
//TODO error checking not working with OpenAPI methods
|
||||||
console.log("Error", err)
|
console.log("Error", err)
|
||||||
this.makeToast(this.$t("Error"), err.bodyText, "danger")
|
makeToast(this.$t("Error"), err.bodyText, "danger")
|
||||||
})
|
})
|
||||||
|
|
||||||
if (automate) {
|
if (automate) {
|
||||||
@ -390,7 +390,7 @@ export default {
|
|||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.log(err)
|
console.log(err)
|
||||||
this.makeToast(this.$t("Error"), err.bodyText, "danger")
|
makeToast(this.$t("Error"), err.bodyText, "danger")
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
getRecipes: function (col, item) {
|
getRecipes: function (col, item) {
|
||||||
@ -410,7 +410,7 @@ export default {
|
|||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.log(err)
|
console.log(err)
|
||||||
this.makeToast(this.$t("Error"), err.bodyText, "danger")
|
makeToast(this.$t("Error"), err.bodyText, "danger")
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
refreshThis: function (id) {
|
refreshThis: function (id) {
|
||||||
|
Loading…
Reference in New Issue
Block a user