Tuesday, November 1, 2011

Re: Set of choices of which several can be chosen without using a ManyToManyField

On Tue, Nov 1, 2011 at 11:07 AM, Jaroslav Dobrek
<jaroslav.dobrek@gmail.com> wrote:
> Hello,
>
> what is the most straightforward way to use a set of choices of which
> several can be chosen without using a ManyToManyField?
>
> Using a ManyToManyField would make my program unnecessarily
> complicated.
>
> Example:
>
> class Candidate(models.Model):
>
>    programming_languages = models.MultipleChoiceField(max_length=50,
> choices=( # replace MultipleChoiceField with existing possibility
>
>            (u'Python)', u'Python'),
>            (u'C++', u'C++'),
>            (u'Java', u'Java'),
>            # ...
>            ), blank=True)
>
> Jaroslav
>

You are confusing model fields with form fields. MultipleChoiceField
is a form field, not a model field.

If you want a field that will be represented by a MultipleChoiceField
in model, you simply need to define 'choices' on a field class.

https://docs.djangoproject.com/en/1.3/ref/models/fields/#choices

Cheers

Tom

--
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.

No comments:

Post a Comment