Discussion:
RadioSelect widget in Django 1.1 using Model Form
Ricardo L. Dani
2010-11-03 15:03:19 UTC
Permalink
Hello,

I'm working with an project using django-cms and django 1.1 and I have this
problem:

With a big model form with many choice charFields must be reendered as
<input type="radio"> and not as <select>'s (default)

Ex:

field = models.CharField(max_length=1, default=None, choices=CHOICES)

renders:

<select>
<option>
... etc

but i need a <input type="option">

With django 1.2 i get this using:

class InscricaoForm(ModelForm):

class Meta:
model = Inscricao
widgets ={
'possiveis_areas_de_interesse' : RadioSelect,
'regime_dedicacao_curso' : RadioSelect,
'vinculo_empregaticio' : RadioSelect,
'interesse_bolsa_estudos' : RadioSelect,
'conhecimento_linguas_estrangeiras' : RadioSelect
}

but I use django-cms and this not works fine with django 1.2

the question: how i do that with django 1.1 ?

thanks

Ps: sorry for the bad english :/
--
Ricardo Lapa Dani
Graduando em Ciência da Computação
Universidade Federal de Ouro Preto
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com.
To unsubscribe from this group, send email to django-users+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Daniel Roseman
2010-11-03 15:21:52 UTC
Permalink
Post by Ricardo L. Dani
Hello,
I'm working with an project using django-cms and django 1.1 and I have this
With a big model form with many choice charFields must be reendered as
<input type="radio"> and not as <select>'s (default)
    field = models.CharField(max_length=1, default=None, choices=CHOICES)
    <select>
        <option>
        ... etc
but i need a <input type="option">
        model = Inscricao
        widgets ={
            'possiveis_areas_de_interesse' : RadioSelect,
            'regime_dedicacao_curso' : RadioSelect,
            'vinculo_empregaticio' : RadioSelect,
            'interesse_bolsa_estudos' : RadioSelect,
            'conhecimento_linguas_estrangeiras' : RadioSelect
        }
but I use django-cms and this not works fine with django 1.2
the question: how i do that with django 1.1 ?
thanks
Ps: sorry for the bad english :/
Your English is fine.

You have to overwrite the field declaration for each one you want to
change, specifying the `widget` argument:

class InscricaoForm(ModelForm):
possiveis_areas_de_interesse =
forms.ChoiceField(choices=FOO_CHOICES, widget=forms.RadioSelect)

etc. You have to remember to include all the options you've defined
for your model field - default, max_length, is_required. It's
unfortunately very verbose, which is why the `widgets` syntax was
introduced in version 1.2.
--
DR.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com.
To unsubscribe from this group, send email to django-users+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Ricardo L. Dani
2010-11-03 15:51:41 UTC
Permalink
Thanks Daniel,

Now it makes sense.

Thank you again
Post by Daniel Roseman
Post by Ricardo L. Dani
Hello,
I'm working with an project using django-cms and django 1.1 and I have
this
Post by Ricardo L. Dani
With a big model form with many choice charFields must be reendered as
<input type="radio"> and not as <select>'s (default)
field = models.CharField(max_length=1, default=None, choices=CHOICES)
<select>
<option>
... etc
but i need a <input type="option">
model = Inscricao
widgets ={
'possiveis_areas_de_interesse' : RadioSelect,
'regime_dedicacao_curso' : RadioSelect,
'vinculo_empregaticio' : RadioSelect,
'interesse_bolsa_estudos' : RadioSelect,
'conhecimento_linguas_estrangeiras' : RadioSelect
}
but I use django-cms and this not works fine with django 1.2
the question: how i do that with django 1.1 ?
thanks
Ps: sorry for the bad english :/
Your English is fine.
You have to overwrite the field declaration for each one you want to
possiveis_areas_de_interesse =
forms.ChoiceField(choices=FOO_CHOICES, widget=forms.RadioSelect)
etc. You have to remember to include all the options you've defined
for your model field - default, max_length, is_required. It's
unfortunately very verbose, which is why the `widgets` syntax was
introduced in version 1.2.
--
DR.
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group, send email to
.
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.
--
Ricardo Lapa Dani
Graduando em Ciência da Computação
Universidade Federal de Ouro Preto
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com.
To unsubscribe from this group, send email to django-users+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Loading...