finishes shopping lists
This commit is contained in:
parent
711dfbe55f
commit
7bc09dfe89
@ -2,7 +2,7 @@ import django_filters
|
|||||||
from django.contrib.postgres.search import TrigramSimilarity
|
from django.contrib.postgres.search import TrigramSimilarity
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from cookbook.forms import MultiSelectWidget
|
from cookbook.forms import MultiSelectWidget
|
||||||
from cookbook.models import Recipe, Keyword, Food
|
from cookbook.models import Recipe, Keyword, Food, ShoppingList
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
|
|
||||||
@ -52,3 +52,9 @@ class IngredientFilter(django_filters.FilterSet):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = Food
|
model = Food
|
||||||
fields = ['name']
|
fields = ['name']
|
||||||
|
|
||||||
|
|
||||||
|
class ShoppingListFilter(django_filters.FilterSet):
|
||||||
|
class Meta:
|
||||||
|
model = ShoppingList
|
||||||
|
fields = ['finished']
|
||||||
|
18
cookbook/migrations/0089_shoppinglist_finished.py
Normal file
18
cookbook/migrations/0089_shoppinglist_finished.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 3.1.1 on 2020-09-29 11:55
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('cookbook', '0088_auto_20200929_1202'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='shoppinglist',
|
||||||
|
name='finished',
|
||||||
|
field=models.BooleanField(default=False),
|
||||||
|
),
|
||||||
|
]
|
@ -312,6 +312,7 @@ class ShoppingList(models.Model):
|
|||||||
recipes = models.ManyToManyField(ShoppingListRecipe, blank=True)
|
recipes = models.ManyToManyField(ShoppingListRecipe, blank=True)
|
||||||
entries = models.ManyToManyField(ShoppingListEntry, 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')
|
||||||
|
finished = models.BooleanField(default=False)
|
||||||
created_by = models.ForeignKey(User, on_delete=models.CASCADE)
|
created_by = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||||
created_at = models.DateTimeField(auto_now_add=True)
|
created_at = models.DateTimeField(auto_now_add=True)
|
||||||
|
|
||||||
|
@ -234,7 +234,7 @@ class ShoppingListSerializer(WritableNestedModelSerializer):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = ShoppingList
|
model = ShoppingList
|
||||||
fields = ('id', 'uuid', 'note', 'recipes', 'entries', 'shared', 'created_by', 'created_at',)
|
fields = ('id', 'uuid', 'note', 'recipes', 'entries', 'shared', 'finished', 'created_by', 'created_at',)
|
||||||
read_only_fields = ('id',)
|
read_only_fields = ('id',)
|
||||||
|
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ class ShoppingListTable(tables.Table):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = ShoppingList
|
model = ShoppingList
|
||||||
template_name = 'generic/table_template.html'
|
template_name = 'generic/table_template.html'
|
||||||
fields = ('id', 'created_by', 'created_at')
|
fields = ('id', 'finished', 'created_by', 'created_at')
|
||||||
|
|
||||||
|
|
||||||
class InviteLinkTable(tables.Table):
|
class InviteLinkTable(tables.Table):
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
<div class="table-container">
|
<div class="table-container">
|
||||||
<h3>{{ title }} {% trans 'List' %}
|
<h3 style="margin-bottom: 2vh">{{ title }} {% trans 'List' %}
|
||||||
{% if create_url %}
|
{% if create_url %}
|
||||||
<a href="{% url create_url %}"> <i class="fas fa-plus-circle"></i>
|
<a href="{% url create_url %}"> <i class="fas fa-plus-circle"></i>
|
||||||
</a>
|
</a>
|
||||||
|
@ -183,6 +183,17 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col" style="text-align: right; margin-top: 1vh">
|
||||||
|
|
||||||
|
<div class="form-group form-check form-group-lg">
|
||||||
|
<input class="form-check-input" style="zoom:1.3;" type="checkbox" v-model="shopping_list.finished" id="id_finished">
|
||||||
|
<label class="form-check-label" style="zoom:1.3;" for="id_finished"> {% trans 'Finished' %}</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div v-else>
|
<div v-else>
|
||||||
|
|
||||||
@ -450,7 +461,7 @@
|
|||||||
console.log("proceeding to update shopping list", this.shopping_list)
|
console.log("proceeding to update shopping list", this.shopping_list)
|
||||||
|
|
||||||
if (this.shopping_list_id === null) {
|
if (this.shopping_list_id === null) {
|
||||||
this.$http.post("{% url 'api:shoppinglist-list' %}", this.shopping_list, {}).then((response) => {
|
return this.$http.post("{% url 'api:shoppinglist-list' %}", this.shopping_list, {}).then((response) => {
|
||||||
console.log(response)
|
console.log(response)
|
||||||
this.makeToast('{% trans 'Updated' %}', '{% trans 'Object created successfully!' %}', 'success')
|
this.makeToast('{% trans 'Updated' %}', '{% trans 'Object created successfully!' %}', 'success')
|
||||||
this.loading = false
|
this.loading = false
|
||||||
@ -465,7 +476,7 @@
|
|||||||
this.loading = false
|
this.loading = false
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
this.$http.put("{% url 'api:shoppinglist-detail' shopping_list_id %}", this.shopping_list, {}).then((response) => {
|
return this.$http.put("{% url 'api:shoppinglist-detail' shopping_list_id %}", this.shopping_list, {}).then((response) => {
|
||||||
console.log(response)
|
console.log(response)
|
||||||
this.shopping_list = response.body
|
this.shopping_list = response.body
|
||||||
this.makeToast('{% trans 'Updated' %}', '{% trans 'Changes saved successfully!' %}', 'success')
|
this.makeToast('{% trans 'Updated' %}', '{% trans 'Changes saved successfully!' %}', 'success')
|
||||||
|
@ -6,7 +6,7 @@ from django.shortcuts import render
|
|||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
from django_tables2 import RequestConfig
|
from django_tables2 import RequestConfig
|
||||||
|
|
||||||
from cookbook.filters import IngredientFilter
|
from cookbook.filters import IngredientFilter, ShoppingListFilter
|
||||||
from cookbook.helper.permission_helper import group_required
|
from cookbook.helper.permission_helper import group_required
|
||||||
from cookbook.models import Keyword, SyncLog, RecipeImport, Storage, Food, ShoppingList, InviteLink
|
from cookbook.models import Keyword, SyncLog, RecipeImport, Storage, Food, ShoppingList, InviteLink
|
||||||
from cookbook.tables import KeywordTable, ImportLogTable, RecipeImportTable, StorageTable, IngredientTable, ShoppingListTable, InviteLinkTable
|
from cookbook.tables import KeywordTable, ImportLogTable, RecipeImportTable, StorageTable, IngredientTable, ShoppingListTable, InviteLinkTable
|
||||||
@ -49,10 +49,12 @@ def food(request):
|
|||||||
|
|
||||||
@group_required('user')
|
@group_required('user')
|
||||||
def shopping_list(request):
|
def shopping_list(request):
|
||||||
table = ShoppingListTable(ShoppingList.objects.filter(created_by=request.user).all())
|
f = ShoppingListFilter(request.GET, queryset=ShoppingList.objects.filter(created_by=request.user).all().order_by('finished', 'created_at'))
|
||||||
|
|
||||||
|
table = ShoppingListTable(f.qs)
|
||||||
RequestConfig(request, paginate={'per_page': 25}).configure(table)
|
RequestConfig(request, paginate={'per_page': 25}).configure(table)
|
||||||
|
|
||||||
return render(request, 'generic/list_template.html', {'title': _("Shopping Lists"), 'table': table, 'create_url': 'view_shopping'})
|
return render(request, 'generic/list_template.html', {'title': _("Shopping Lists"), 'table': table, 'filter': f, 'create_url': 'view_shopping'})
|
||||||
|
|
||||||
|
|
||||||
@group_required('admin')
|
@group_required('admin')
|
||||||
|
Loading…
Reference in New Issue
Block a user