mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-04 05:39:00 -05:00
supermarket shopping list relation
This commit is contained in:
19
cookbook/migrations/0106_shoppinglist_supermarket.py
Normal file
19
cookbook/migrations/0106_shoppinglist_supermarket.py
Normal file
@@ -0,0 +1,19 @@
|
||||
# Generated by Django 3.1.5 on 2021-01-26 15:21
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0105_auto_20210126_1604'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='shoppinglist',
|
||||
name='supermarket',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='cookbook.supermarket'),
|
||||
),
|
||||
]
|
||||
@@ -430,9 +430,8 @@ class ShoppingList(models.Model):
|
||||
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'
|
||||
)
|
||||
shared = models.ManyToManyField(User, blank=True, related_name='list_share')
|
||||
supermarket = models.ForeignKey(Supermarket, null=True, blank=True, on_delete=models.SET_NULL)
|
||||
finished = models.BooleanField(default=False)
|
||||
created_by = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
@@ -362,12 +362,13 @@ class ShoppingListSerializer(WritableNestedModelSerializer):
|
||||
recipes = ShoppingListRecipeSerializer(many=True, allow_null=True)
|
||||
entries = ShoppingListEntrySerializer(many=True, allow_null=True)
|
||||
shared = UserNameSerializer(many=True)
|
||||
supermarket = SupermarketSerializer(allow_null=True)
|
||||
|
||||
class Meta:
|
||||
model = ShoppingList
|
||||
fields = (
|
||||
'id', 'uuid', 'note', 'recipes', 'entries',
|
||||
'shared', 'finished', 'created_by', 'created_at'
|
||||
'shared', 'finished', 'supermarket', 'created_by', 'created_at'
|
||||
)
|
||||
read_only_fields = ('id',)
|
||||
|
||||
|
||||
@@ -112,10 +112,12 @@
|
||||
<table class="table table-sm table-striped" style="margin-top: 1vh">
|
||||
<tbody>
|
||||
<template v-for="c in display_entries">
|
||||
|
||||
|
||||
<tr>
|
||||
<td colspan="4">[[c.name]]</td>
|
||||
</tr>
|
||||
|
||||
<tr v-for="(element, index) in c.entries" :key="element.id">
|
||||
<!--<td class="handle"><i class="fas fa-sort"></i></td>-->
|
||||
<td class="handle"><i class="fas fa-sort"></i></td>
|
||||
<td>[[element.amount]]</td>
|
||||
<td>[[element.unit.name]]</td>
|
||||
<td>[[element.food.name]]</td>
|
||||
@@ -203,22 +205,22 @@
|
||||
|
||||
<div class="row">
|
||||
<div class="col" style="margin-top: 1vh">
|
||||
{# <multiselect#}
|
||||
{# v-tabindex#}
|
||||
{# v-model="shopping_list.shared"#}
|
||||
{# :options="users"#}
|
||||
{# :close-on-select="true"#}
|
||||
{# :clear-on-select="true"#}
|
||||
{# :allow-empty="true"#}
|
||||
{# :preserve-search="true"#}
|
||||
{# placeholder="{% trans 'Select Supermarket' %}"#}
|
||||
{# select-label="{% trans 'Select' %}"#}
|
||||
{# label="supermarket"#}
|
||||
{# track-by="id"#}
|
||||
{# :multiple="false"#}
|
||||
{# :loading="supermarket_loading"#}
|
||||
{# @search-change="searchSupermarket">#}
|
||||
{# </multiselect>#}
|
||||
<multiselect
|
||||
v-tabindex
|
||||
v-model="shopping_list.supermarket"
|
||||
:options="supermarkets"
|
||||
:close-on-select="true"
|
||||
:clear-on-select="true"
|
||||
:allow-empty="true"
|
||||
:preserve-search="true"
|
||||
placeholder="{% trans 'Select Supermarket' %}"
|
||||
select-label="{% trans 'Select' %}"
|
||||
label="name"
|
||||
track-by="id"
|
||||
:multiple="false"
|
||||
:loading="supermarkets_loading"
|
||||
@search-change="searchSupermarket">
|
||||
</multiselect>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
@@ -360,7 +362,7 @@
|
||||
data: {
|
||||
shopping_list_id: {% if shopping_list_id %}{{ shopping_list_id }}{% else %}null{% endif %},
|
||||
loading: true,
|
||||
edit_mode: false,
|
||||
edit_mode: true,
|
||||
export_text_prefix: '', //TODO add userpreference
|
||||
recipe_query: '',
|
||||
recipes: [],
|
||||
@@ -374,6 +376,8 @@
|
||||
foods_loading: false,
|
||||
units: [],
|
||||
units_loading: false,
|
||||
supermarkets: [],
|
||||
supermarkets_loading: false,
|
||||
users: [],
|
||||
users_loading: false,
|
||||
onLine: navigator.onLine,
|
||||
@@ -473,6 +477,7 @@
|
||||
{% endif %}
|
||||
|
||||
this.searchUsers('')
|
||||
this.searchSupermarket('')
|
||||
},
|
||||
methods: {
|
||||
findMergeEntry: function (categories, entry) {
|
||||
@@ -756,6 +761,17 @@
|
||||
this.makeToast(gettext('Error'), gettext('There was an error loading a resource!') + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
searchSupermarket: function (query) { //TODO move to central component
|
||||
this.supermarkets_loading = true
|
||||
this.$http.get("{% url 'api:supermarket-list' %}" + '?query=' + query + '&limit=10').then((response) => {
|
||||
this.supermarkets = response.data
|
||||
this.supermarkets_loading = false
|
||||
}).catch((err) => {
|
||||
this.makeToast(gettext('Error'), gettext('There was an error loading a resource!') + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
},
|
||||
beforeDestroy() {
|
||||
window.removeEventListener('online', this.updateOnlineStatus);
|
||||
|
||||
Reference in New Issue
Block a user