voss
You've defined your form to expect a `request` argument, but then you
haven't passed that argument.
>
> answer = MyForm(request, request.GET or None)
> --
> DR.
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/3eYgahTEsy8J.
> 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.
I think this is because you are abusing your model form, and hence it
is not valid.
You should not be setting choices on a ModelMultipleChoiceField, you
should be supplying a queryset that describes the choices you want.
When validating the form, django will check that the submitted values
are contained in the ModelMultipleChoiceField's queryset.
Furthermore, ModelMultipleChoiceField will normally have id ->
description mapping, where as you have description -> description, eg
it should generate this HTML - <option value="2">London</option>,
where as you have it generating <option
value="London">London</option>. It's just wrong. I guess you are
trying to do this to control the label generated - you should be doing
this[1].
So recap:
Don't assign choices to a ModelMultipleChoiceField, assign a queryset
Use a custom ModelMultipleChoiceField subclass to control how each
model is displayed.
Cheers
Tom
[1] https://docs.djangoproject.com/en/1.3/ref/forms/fields/#modelchoicefield
I can't link to the block of text directly, look for this:
"""
The __unicode__ method of the model will be called to generate string
representations of the objects for use in the field's choices; to
provide customized representations, subclass ModelChoiceField and
override label_from_instance. This method will receive a model object,
and should return a string suitable for representing it.
"""