Q:

Problem with CheckboxSelectMultiple and ManyToManyField with Modelform

I am quite new to Django(4months actually), I am struggling with this problem for last 2 days, I think I am making some stupid mistake. Any help or input is highly appreciated. I am using Django 1.3. 
In the model I have,
BUSINESS_GROUP = (
    ('MNC','Multinational'),
    ('INT','International (Export/Import)'),
    ('DOM','Domestic/National'),
    ('LOC','Local'),
    ('VIR','Virtual'),
)

class BusinessGroup(models.Model):
    bgroup_type = models.CharField(max_length=15, choices = BUSINESS_GROUP, blank = True, null = True)

class Business(models.Model):
    business_group_choices = models.ManyToManyField(BusinessGroup, verbose_name= "Business Group")

In Form I have something like,
def __init__(self, *args, **kwargs):
    super(BusinessForm, self).__init__(*args, **kwargs)
    self.fields['business_group_choices'].widget = forms.CheckboxSelectMultiple(choices=BUSINESS_GROUP)

In the view,
if request.method == 'POST':
    form = BusinessForm(request.POST, instance = business)
    if form.is_valid():
        new_business = form.save(commit=False)
        new_business.created_by = request.user
        form_values = form.cleaned_data
        new_business.save()
        assign('edit_business', request.user, new_business)
        return HttpResponseRedirect(new_business.get_absolute_url())

I am getting errors like,
"DOM" is not a valid value for a primary key.
"INT" is not a valid value for a primary key.

etc.
I found source of error here in Django model source,
But not clear how to interpret and workout this problem.
Edit:
I tried making fields null=True and/or blank=True still I get the validation error, why?
With some changes on the whole set-up I got this new error,
Select a valid choice. [u'MNC', u'INT', u'DOM', u'LOC', u'VIR'] is not one of the available choices.

New setup:
In the model
class BusinessGroup(models.Model):
        bgroup_type = models.CharField(max_length=15)

class Business(models.Model):
    business_group_choices = models.ManyToManyField(BusinessGroup, verbose_name= "Business Group", choices=BUSINESS_GROUP)

In Form I have something like,
def __init__(self, *args, **kwargs):
    super(BusinessForm, self).__init__(*args, **kwargs)
    self.fields['business_group_choices'].widget = forms.CheckboxSelectMultiple(choices=BUSINESS_GROUP)

A:

There are a couple of things I would change...
First, I try to avoid "magic strings" wherever I can. Instead of:
BUSINESS_GROUP = (
    ('MNC','Multinational'),
    ('INT','International (Export/Import)'),
    ('DOM','Domestic/National'),
    ('LOC','Local'),
    ('VIR','Virtual'),
)

I would do:
#in my_app > constants.py
MNC = 0
INT = 1
DOM = 2
LOC = 3
VIR = 4

BUSINESS_GROUP_CHOICES = (
    (MNC, 'Multinational'),
    (INT, 'International (Export/Import)'),
    (DOM, 'Domestic/National'),
    (LOC, 'Local'),
    (VIR, 'Virtual'),
)

This necessitates a change in your model, and I've changed the field names to be a little clearer:
from django.db import models

from businesses.constants import BUSINESS_GROUP_CHOICES, MNC

class BusinessGroup(models.Model):
    business_group_type = models.IntegerField(choices=BUSINESS_GROUP_CHOICES,
        default=MNC)

    def __unicode__(self):
        choices_dict = dict(BUSINESS_GROUP_CHOICES)
        return choices_dict[self.business_group_type]

class Business(models.Model):
    business_groups = models.ManyToManyField(BusinessGroup)

The real problem is in your form. Instead of just re-defining the widget, you need to be using a ModelMultipleChoiceField, as such:
from django import forms

from businesses.models import BusinessGroup

class BusinessForm(forms.ModelForm):
    class Meta:
        model = Business

    business_group = forms.ModelMultipleChoiceField(queryset=BusinessGroup.objects.all(),
                                                    widget=forms.CheckboxSelectMultiple())

That's why you were getting a primary key error. Your BUSINESS_GROUP is just a tuple. Django was trying to assign the value from the tuple from your choices as the primary key, which obviously it can't do. Instead, what the ModelMultipleChoiceField will do, is relate the instance of the BusinessGroup you selected to your Business.
Hope that helps you out.

