1👍
✅
You need filter query for Category
not Task
. Also, pop passed user
parameter before calling init of super.
class TaskForm(ModelForm):
class Meta:
model = Task
exclude = ['owner']
def __init__(self, user, *args, **kwargs):
userid = kwargs.pop('user')
super(TaskForm, self).__init__(*args, **kwargs)
self.fields['category'].queryset = Category.objects.filter(user__id=userid)
# assuming your Category model has user foreignkey/onetone field.
Source:stackexchange.com