fixed keywords and food/unit loading
This commit is contained in:
@ -125,9 +125,6 @@ class Keyword(models.Model):
|
|||||||
else:
|
else:
|
||||||
return f"{self.name}"
|
return f"{self.name}"
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return self.name
|
|
||||||
|
|
||||||
|
|
||||||
class Unit(models.Model):
|
class Unit(models.Model):
|
||||||
name = models.CharField(unique=True, max_length=128)
|
name = models.CharField(unique=True, max_length=128)
|
||||||
|
@ -58,6 +58,11 @@ class SyncLogSerializer(serializers.ModelSerializer):
|
|||||||
|
|
||||||
|
|
||||||
class KeywordSerializer(UniqueFieldsMixin, serializers.ModelSerializer):
|
class KeywordSerializer(UniqueFieldsMixin, serializers.ModelSerializer):
|
||||||
|
label = serializers.SerializerMethodField('get_label')
|
||||||
|
|
||||||
|
def get_label(self, obj):
|
||||||
|
return str(obj)
|
||||||
|
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
# since multi select tags dont have id's duplicate names might be routed to create
|
# since multi select tags dont have id's duplicate names might be routed to create
|
||||||
obj, created = Keyword.objects.get_or_create(**validated_data)
|
obj, created = Keyword.objects.get_or_create(**validated_data)
|
||||||
@ -65,7 +70,7 @@ class KeywordSerializer(UniqueFieldsMixin, serializers.ModelSerializer):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Keyword
|
model = Keyword
|
||||||
fields = ('id', 'name', 'icon', 'description', 'created_by', 'created_at', 'updated_at')
|
fields = ('id', 'name', 'icon', 'label', 'description', 'created_by', 'created_at', 'updated_at')
|
||||||
|
|
||||||
read_only_fields = ('id',)
|
read_only_fields = ('id',)
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@
|
|||||||
:hide-selected="true"
|
:hide-selected="true"
|
||||||
:preserve-search="true"
|
:preserve-search="true"
|
||||||
placeholder="{% trans 'Select Keywords' %}"
|
placeholder="{% trans 'Select Keywords' %}"
|
||||||
label="name"
|
label="label"
|
||||||
track-by="id"
|
track-by="id"
|
||||||
id="id_keywords"
|
id="id_keywords"
|
||||||
:multiple="true"
|
:multiple="true"
|
||||||
@ -409,7 +409,7 @@
|
|||||||
if (this.recipe !== undefined) {
|
if (this.recipe !== undefined) {
|
||||||
for (let s of this.recipe.steps) {
|
for (let s of this.recipe.steps) {
|
||||||
for (let i of s.ingredients) {
|
for (let i of s.ingredients) {
|
||||||
if (i.unit.id === undefined) {
|
if (i.unit !== undefined &&i.unit.id === undefined) {
|
||||||
this.units.push(i.unit)
|
this.units.push(i.unit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -428,7 +428,7 @@
|
|||||||
if (this.recipe !== undefined) {
|
if (this.recipe !== undefined) {
|
||||||
for (let s of this.recipe.steps) {
|
for (let s of this.recipe.steps) {
|
||||||
for (let i of s.ingredients) {
|
for (let i of s.ingredients) {
|
||||||
if (i.food.id === undefined) {
|
if (i.food !== undefined &&i.food.id === undefined) {
|
||||||
this.foods.push(i.food)
|
this.foods.push(i.food)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user