added option to set URL on food
This commit is contained in:
parent
74c86f1b6b
commit
b30f8c245e
18
cookbook/migrations/0196_food_url.py
Normal file
18
cookbook/migrations/0196_food_url.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 4.1.10 on 2023-07-22 06:45
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('cookbook', '0195_invitelink_internal_note_userspace_internal_note_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='food',
|
||||||
|
name='url',
|
||||||
|
field=models.CharField(blank=True, default='', max_length=1024, null=True),
|
||||||
|
),
|
||||||
|
]
|
@ -579,6 +579,7 @@ class Food(ExportModelOperationsMixin('food'), TreeModel, PermissionModelMixin):
|
|||||||
name = models.CharField(max_length=128, validators=[MinLengthValidator(1)])
|
name = models.CharField(max_length=128, validators=[MinLengthValidator(1)])
|
||||||
plural_name = models.CharField(max_length=128, null=True, blank=True, default=None)
|
plural_name = models.CharField(max_length=128, null=True, blank=True, default=None)
|
||||||
recipe = models.ForeignKey('Recipe', null=True, blank=True, on_delete=models.SET_NULL)
|
recipe = models.ForeignKey('Recipe', null=True, blank=True, on_delete=models.SET_NULL)
|
||||||
|
url = models.CharField(max_length=1024, blank=True, null=True, default='')
|
||||||
supermarket_category = models.ForeignKey(SupermarketCategory, null=True, blank=True, on_delete=models.SET_NULL) # inherited field
|
supermarket_category = models.ForeignKey(SupermarketCategory, null=True, blank=True, on_delete=models.SET_NULL) # inherited field
|
||||||
ignore_shopping = models.BooleanField(default=False) # inherited field
|
ignore_shopping = models.BooleanField(default=False) # inherited field
|
||||||
onhand_users = models.ManyToManyField(User, blank=True)
|
onhand_users = models.ManyToManyField(User, blank=True)
|
||||||
|
@ -684,7 +684,7 @@ class FoodSerializer(UniqueFieldsMixin, WritableNestedModelSerializer, ExtendedR
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = Food
|
model = Food
|
||||||
fields = (
|
fields = (
|
||||||
'id', 'name', 'plural_name', 'description', 'shopping', 'recipe',
|
'id', 'name', 'plural_name', 'description', 'shopping', 'recipe', 'url',
|
||||||
'properties', 'properties_food_amount', 'properties_food_unit',
|
'properties', 'properties_food_amount', 'properties_food_unit',
|
||||||
'food_onhand', 'supermarket_category',
|
'food_onhand', 'supermarket_category',
|
||||||
'image', 'parent', 'numchild', 'numrecipe', 'inherit_fields', 'full_name', 'ignore_shopping',
|
'image', 'parent', 'numchild', 'numrecipe', 'inherit_fields', 'full_name', 'ignore_shopping',
|
||||||
|
@ -170,6 +170,10 @@
|
|||||||
></generic-multiselect>
|
></generic-multiselect>
|
||||||
</b-form-group>
|
</b-form-group>
|
||||||
|
|
||||||
|
<b-form-group :label="$t('URL')" description="">
|
||||||
|
<b-form-input v-model="food.url"></b-form-input>
|
||||||
|
</b-form-group>
|
||||||
|
|
||||||
<b-form-group :description="$t('OnHand_help')">
|
<b-form-group :description="$t('OnHand_help')">
|
||||||
<b-form-checkbox v-model="food.food_onhand">{{ $t('OnHand') }}</b-form-checkbox>
|
<b-form-checkbox v-model="food.food_onhand">{{ $t('OnHand') }}</b-form-checkbox>
|
||||||
</b-form-group>
|
</b-form-group>
|
||||||
@ -309,6 +313,7 @@ export default {
|
|||||||
description: "",
|
description: "",
|
||||||
shopping: false,
|
shopping: false,
|
||||||
recipe: null,
|
recipe: null,
|
||||||
|
url: '',
|
||||||
properties: [],
|
properties: [],
|
||||||
properties_food_amount: 100,
|
properties_food_amount: 100,
|
||||||
properties_food_unit: {name: 'g'},
|
properties_food_unit: {name: 'g'},
|
||||||
|
@ -30,21 +30,13 @@
|
|||||||
</td>
|
</td>
|
||||||
<td @click="done">
|
<td @click="done">
|
||||||
<template v-if="ingredient.food !== null">
|
<template v-if="ingredient.food !== null">
|
||||||
<a :href="resolveDjangoUrl('view_recipe', ingredient.food.recipe.id)" v-if="ingredient.food.recipe !== null" target="_blank" rel="noopener noreferrer">{{
|
<a :href="resolveDjangoUrl('view_recipe', ingredient.food.recipe.id)" v-if="ingredient.food.recipe !== null" target="_blank" rel="noopener noreferrer">
|
||||||
ingredient.food.name
|
{{ ingredientName(ingredient) }}
|
||||||
}}</a>
|
</a>
|
||||||
<template v-if="ingredient.food.recipe === null">
|
<a :href="ingredient.food.url" v-else-if="ingredient.food.url !== ''" target="_blank" rel="noopener noreferrer">
|
||||||
<template>
|
{{ ingredientName(ingredient) }}</a>
|
||||||
<template v-if="ingredient.food.plural_name === '' || ingredient.food.plural_name === null">
|
|
||||||
<span>{{ ingredient.food.name }}</span>
|
|
||||||
</template>
|
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<span v-if="ingredient.always_use_plural_food">{{ ingredient.food.plural_name }}</span>
|
<span>{{ ingredientName(ingredient) }}</span>
|
||||||
<span v-else-if="ingredient.no_amount">{{ ingredient.food.name }}</span>
|
|
||||||
<span v-else-if="ingredient.amount * this.ingredient_factor > 1">{{ ingredient.food.plural_name }}</span>
|
|
||||||
<span v-else>{{ ingredient.food.name }}</span>
|
|
||||||
</template>
|
|
||||||
</template>
|
|
||||||
</template>
|
</template>
|
||||||
</template>
|
</template>
|
||||||
</td>
|
</td>
|
||||||
@ -62,7 +54,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { calculateAmount, ResolveUrlMixin } from "@/utils/utils"
|
import {calculateAmount, ResolveUrlMixin} from "@/utils/utils"
|
||||||
|
|
||||||
import Vue from "vue"
|
import Vue from "vue"
|
||||||
import VueSanitize from "vue-sanitize"
|
import VueSanitize from "vue-sanitize"
|
||||||
@ -73,8 +65,8 @@ export default {
|
|||||||
name: "IngredientComponent",
|
name: "IngredientComponent",
|
||||||
props: {
|
props: {
|
||||||
ingredient: Object,
|
ingredient: Object,
|
||||||
ingredient_factor: { type: Number, default: 1 },
|
ingredient_factor: {type: Number, default: 1},
|
||||||
detailed: { type: Boolean, default: true },
|
detailed: {type: Boolean, default: true},
|
||||||
},
|
},
|
||||||
mixins: [ResolveUrlMixin],
|
mixins: [ResolveUrlMixin],
|
||||||
data() {
|
data() {
|
||||||
@ -83,7 +75,8 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {},
|
watch: {},
|
||||||
mounted() {},
|
mounted() {
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
calculateAmount: function (x) {
|
calculateAmount: function (x) {
|
||||||
return this.$sanitize(calculateAmount(x, this.ingredient_factor))
|
return this.$sanitize(calculateAmount(x, this.ingredient_factor))
|
||||||
@ -92,6 +85,20 @@ export default {
|
|||||||
done: function () {
|
done: function () {
|
||||||
this.$emit("checked-state-changed", this.ingredient)
|
this.$emit("checked-state-changed", this.ingredient)
|
||||||
},
|
},
|
||||||
|
ingredientName: function (ingredient) {
|
||||||
|
if (ingredient.food.plural_name == null || ingredient.food.plural_name === '') {
|
||||||
|
return ingredient.food.name
|
||||||
|
}
|
||||||
|
if (ingredient.always_use_plural_food) {
|
||||||
|
return ingredient.food.plural_name
|
||||||
|
} else if (ingredient.no_amount) {
|
||||||
|
return ingredient.food.name
|
||||||
|
} else if (ingredient.amount * this.ingredient_factor > 1) {
|
||||||
|
return ingredient.food.plural_name
|
||||||
|
} else {
|
||||||
|
return ingredient.food.name
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
Reference in New Issue
Block a user