Limit values in the modelformset field

前端 未结 2 1961
别跟我提以往
别跟我提以往 2021-01-28 00:06

I\'ve been trying to solve this problem for a couple of days now, getting quite desperate. See the commented out code snippets for some of the things I\'ve tried but didn\'t wor

2条回答
  •  一生所求
    2021-01-28 00:52

    You don't need any kind of custom forms. You can change the queryset of category field as:

    IngrFormSet = modelformset_factory(Ingredient, extra=1, fields=('name', 'category'))
    IngrFormSet.form.base_fields['category'].queryset = Category.objects.filter(user__id=request.user.id)
    

提交回复
热议问题