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)

I am not sure which is correct approach, I am sorry to say but this is
first I am stuck with poor documentation of Django.
Please!! Any input is greatly appreciated

cheers
Abhishek


On Jun 18, 12:17 pm, Abhishek Tiwari <abhishek....@gmail.com> wrote:
> Hi Everyone,
> 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, so old
> (1.1 -) solutions are not helpful much actually there are many on
> stack-overflow.
>
> 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 am doing like,
>
> def __init__(self, *args, **kwargs):
>     self.fields['business_group_choices'].widget =
> forms.CheckboxSelectMultiple(choices=BUSINESS_GROUP)
>
> My view looks like,
>    if request.method == 'POST':
>         form = BusinessForm(request.POST, instance = business)
>         #print request
>         #print form
>         if form.is_valid():
>             new_business = form.save(commit=False)
>             new_business.created_by = request.user
>             new_business.is_blocked=False
>             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 error like this,
>
> "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,http://www.java2s.com/Open-Source/Python/Web-Frameworks/Django/django...
>
> But not clear how to interpret and workout this problem.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to