added sharing to recipe books

This commit is contained in:
vabene1111 2020-05-02 14:15:56 +02:00
parent 64ee18c4d8
commit 349b9629f8
4 changed files with 25 additions and 4 deletions

View File

@ -237,9 +237,8 @@ class ImportRecipeForm(forms.ModelForm):
class RecipeBookForm(forms.ModelForm):
class Meta:
model = RecipeBook
fields = ('name', 'icon', 'description')
widgets = {'icon': EmojiPickerTextInput}
fields = ('name', 'icon', 'description', 'shared')
widgets = {'icon': EmojiPickerTextInput, 'shared': MultiSelectWidget}
class MealPlanForm(forms.ModelForm):

View File

@ -0,0 +1,20 @@
# Generated by Django 3.0.5 on 2020-05-02 12:04
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('cookbook', '0038_auto_20200502_1259'),
]
operations = [
migrations.AddField(
model_name='recipebook',
name='shared',
field=models.ManyToManyField(blank=True, related_name='shared_with', to=settings.AUTH_USER_MODEL),
),
]

View File

@ -197,6 +197,7 @@ class RecipeBook(models.Model):
name = models.CharField(max_length=128)
description = models.TextField(blank=True)
icon = models.CharField(max_length=16, blank=True, null=True)
shared = models.ManyToManyField(User, blank=True, related_name='shared_with')
created_by = models.ForeignKey(User, on_delete=models.CASCADE)
def __str__(self):

View File

@ -4,6 +4,7 @@ from datetime import datetime, timedelta
from django.contrib import messages
from django.contrib.auth import update_session_auth_hash
from django.contrib.auth.forms import PasswordChangeForm
from django.db.models import Q
from django.http import HttpResponseRedirect
from django.shortcuts import render, get_object_or_404
from django.urls import reverse_lazy
@ -86,7 +87,7 @@ def recipe_view(request, pk):
def books(request):
book_list = []
books = RecipeBook.objects.filter(created_by=request.user).all()
books = RecipeBook.objects.filter(Q(created_by=request.user) | Q(shared=request.user)).all()
for b in books:
book_list.append({'book': b, 'recipes': RecipeBookEntry.objects.filter(book=b).all()})