[Django]-Populate CheckboxSelectMultiple with existing data from django model form

0👍

When instantiating the modelForm I wasn’t passing the instance of BlogNotifications model to it. So in the view the form set up looks like:

blogForm = BlogNotificationsForm(instance=BlogNotifications.objects.get(user=request.user))

I hope this may help someone in the future, it really wasn’t that clear in the docs to me!!

1👍

In the view maybe you can set the queryset like this:

form = BlogNotificationsForm()
form.fields["categories"].queryset = Categories.objects.all()

I found this example here

👤balazs

Leave a comment