Tuesday, October 19, 2010

change the default widget to a field in a modelform

Hello list. I have a model with a ManyToMany field.

For example:

----------------------------------------------------------------------
class Table(models.Model):
myField = models.ManyToManyField(OtherTable)
----------------------------------------------------------------------

The modelForm returns a "selectMulttiple" for the field "myField", but
I need a normal "select". Finally the modelForm is something like
this:
----------------------------------------------------------------------
class MyForm(forms.ModelForm):
class Meta:
model = Table
widgets = {
'myField': forms.Select()
}
----------------------------------------------------------------------
This return a form with the normal "select" field.

The problem appear when a want to save the model. I can't save because
the form is invalid. Django say " Introduce a value list". Somebody
have an idea to solve this problem?

If I use a selectMultiple the form is valid and I can save the data.

Thanks for read and sorry for my poor english.

Thanks for read and sorry for my poor english.

P.D. I use Django 1.2.1

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate