super basic shopping list working
This commit is contained in:
parent
fc073124d4
commit
3c73b084cf
18
cookbook/migrations/0076_shoppinglist_entries.py
Normal file
18
cookbook/migrations/0076_shoppinglist_entries.py
Normal file
@ -0,0 +1,18 @@
|
||||
# Generated by Django 3.0.7 on 2020-08-26 18:46
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0075_shoppinglist_shoppinglistentry_shoppinglistrecipe'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='shoppinglist',
|
||||
name='entries',
|
||||
field=models.ManyToManyField(blank=True, to='cookbook.ShoppingListEntry'),
|
||||
),
|
||||
]
|
@ -283,6 +283,7 @@ class ShoppingList(models.Model):
|
||||
uuid = models.UUIDField(default=uuid.uuid4)
|
||||
note = models.TextField(blank=True, null=True)
|
||||
recipes = models.ManyToManyField(ShoppingListRecipe, blank=True)
|
||||
entries = models.ManyToManyField(ShoppingListEntry, blank=True)
|
||||
shared = models.ManyToManyField(User, blank=True, related_name='list_share')
|
||||
created_by = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
@ -209,17 +209,25 @@ class ShoppingListRecipeSerializer(serializers.ModelSerializer):
|
||||
|
||||
|
||||
class ShoppingListEntrySerializer(serializers.ModelSerializer):
|
||||
|
||||
def create(self, validated_data):
|
||||
return ShoppingListEntry.objects.create(**validated_data)
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
return super(ShoppingListEntrySerializer, self).update(instance, validated_data)
|
||||
|
||||
class Meta:
|
||||
model = ShoppingListEntry
|
||||
fields = ('list_recipe', 'food', 'unit', 'amount', 'order', 'checked')
|
||||
|
||||
|
||||
class ShoppingListSerializer(serializers.ModelSerializer):
|
||||
class ShoppingListSerializer(WritableNestedModelSerializer):
|
||||
recipes = ShoppingListRecipeSerializer(many=True, allow_null=True, read_only=True)
|
||||
entries = ShoppingListEntrySerializer(many=True, allow_null=True)
|
||||
|
||||
class Meta:
|
||||
model = ShoppingList
|
||||
fields = ('id', 'uuid', 'note', 'recipes', 'shared', 'created_by', 'created_at',)
|
||||
fields = ('id', 'uuid', 'note', 'recipes', 'entries', 'shared', 'created_by', 'created_at',)
|
||||
|
||||
|
||||
class ShareLinkSerializer(serializers.ModelSerializer):
|
||||
|
@ -30,15 +30,32 @@
|
||||
|
||||
<div v-if="edit_mode">
|
||||
<div class="row">
|
||||
<div class="col col-6">
|
||||
<div class="col col-md-6">
|
||||
<input type="text" class="form-control" v-model="recipe_query" @keyup="getRecipes"
|
||||
placeholder="{% trans 'Search Recipe' %}">
|
||||
|
||||
<ul class="list-group" style="margin-top: 8px">
|
||||
<li class="list-group-item" v-for="x in recipes">[[x.name]]</li>
|
||||
<li class="list-group-item" v-for="x in recipes">[[x.name]]
|
||||
<button @click="addRecipeToList(x)"><i class="fa fa-plus"></i></button>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="col col-md-6">
|
||||
<ul class="list-group" style="margin-top: 8px" v-if="shopping_list !== undefined">
|
||||
<li class="list-group-item" v-for="x in shopping_list.recipes">[[x.recipe.name]] <input
|
||||
type="number" v-model="x.multiplier">
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col col-12">
|
||||
<table>
|
||||
<tr v-for="x in shopping_list.entries">
|
||||
<td>[[x]]</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else>
|
||||
@ -65,6 +82,7 @@
|
||||
edit_mode: true,
|
||||
recipe_query: '',
|
||||
recipes: [],
|
||||
shopping_list: undefined,
|
||||
},
|
||||
directives: {
|
||||
tabindex: {
|
||||
@ -89,6 +107,13 @@
|
||||
*/
|
||||
mounted: function () {
|
||||
|
||||
//TODO default share users
|
||||
this.shopping_list = {
|
||||
"recipes": [],
|
||||
"entries": [],
|
||||
"shared": [],
|
||||
"created_by": 1
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
/*
|
||||
@ -112,6 +137,25 @@
|
||||
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
addRecipeToList: function (recipe) {
|
||||
console.log(this.shopping_list)
|
||||
this.shopping_list.recipes.push({
|
||||
"recipe": recipe,
|
||||
"multiplier": 1
|
||||
})
|
||||
|
||||
for (let s of recipe.steps) {
|
||||
for (let i of s.ingredients) {
|
||||
this.shopping_list.entries.push({
|
||||
'list_recipe': recipe.id,
|
||||
'food': i.food,
|
||||
'unit': i.unit,
|
||||
'amount': i.amount,
|
||||
'order': 0
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
searchKeywords: function (query) {
|
||||
this.keywords_loading = true
|
||||
this.$http.get("{% url 'api:keyword-list' %}" + '?query=' + query + '&limit=10').then((response) => {
|
||||
|
Loading…
Reference in New Issue
Block a user