I have a Profile object with manytomany relationship to Category
class Profile(models.Model):
. . .
category = models.ManyToManyField(Category, blank=True)
In my form, I want to display a checkbox of only the categories associated with the Profile The code below will display all categories.
class ProfileForm(ModelForm):
. . .
category = forms.ModelMultipleChoiceField(Category.objects.all(),
widget=forms.CheckboxSelectMultiple())
How do i write a queryset so that I show only the categories associated with the Profile? I've variations of this:
category = forms.ModelMultipleChoiceField(Category.objects.filter(id__in=Profile.category.all()), widget=forms.CheckboxSelectMultiple())
Has this error: 'ReverseManyRelatedObjectsDescriptor' object has no attribute 'all'