I\'m making a game link site, where users can post links to their favorite web game. When people post games they are supposed to check what category the game falls into.
Here is how I solved it (Edit: and the admin thing)
cats = forms.ModelMultipleChoiceField(widget=forms.CheckboxSelectMultiple, queryset=Category.objects.all())
(It was the queryset part I couldn't find..)
cats = form.cleaned_data['cats']
game.cats = cats
And that's all the code needed to save the data.
Edit: here is a solution for the admin
from django.contrib import admin
from django.forms import CheckboxSelectMultiple
class MyModelAdmin(admin.ModelAdmin):
formfield_overrides = {
models.ManyToManyField: {'widget': CheckboxSelectMultiple},
}
from gamesite.games.models import Game, MyModelAdmin
admin.site.register(Game, MyModelAdmin)
It's kind of quirky in looks, but works! If someone finds a way to make it more "clean" please post!
Cheers!