fixed meal plan form not own type display

This commit is contained in:
vabene1111
2020-07-01 23:29:32 +02:00
parent 0005ca243c
commit 67a4a2627b
2 changed files with 12 additions and 2 deletions

View File

@@ -11,7 +11,7 @@ from django.views.generic import CreateView
from cookbook.forms import ImportRecipeForm, RecipeImport, KeywordForm, Storage, StorageForm, InternalRecipeForm, \
RecipeBookForm, MealPlanForm
from cookbook.helper.permission_helper import GroupRequiredMixin, group_required
from cookbook.models import Keyword, Recipe, RecipeBook, MealPlan, ShareLink
from cookbook.models import Keyword, Recipe, RecipeBook, MealPlan, ShareLink, MealType
class RecipeCreate(GroupRequiredMixin, CreateView):
@@ -132,6 +132,11 @@ class MealPlanCreate(GroupRequiredMixin, CreateView):
form_class = MealPlanForm
success_url = reverse_lazy('view_plan')
def get_form(self, form_class=None):
form = self.form_class(**self.get_form_kwargs())
form.fields['meal_type'].queryset = MealType.objects.filter(created_by=self.request.user).all()
return form
def get_initial(self):
return dict(
meal_type=self.request.GET['meal'] if 'meal' in self.request.GET else None,