[Django]-Set initial value in CreateView from ForeignKey (non-self.request.user)

46👍

You need to instantiate your recipe:

class IngredientAddView(CreateView):
    model=Ingredient

    def get_initial(self):
        recipe = get_object_or_404(Recipe, slug=self.kwargs.get('slug'))
        return {
            'recipe':recipe,
        }

Leave a comment