#21568: ModelMultipleChoiceField + show_hidden_initial + has_changed = TypeError -------------------------+------------------------------------------------- Reporter: | Owner: nobody dibrovsd@… | Status: new Type: Bug | Version: 1.6 Component: Forms | Keywords: ModelMultipleChoiceField Severity: Normal | show_hidden_initial Triage Stage: | Has patch: 0 Unreviewed | UI/UX: 0 Easy pickings: 0 | -------------------------+------------------------------------------------- hi
{{{ def test(request): u""" for debug and test's """ from django import forms from django.http import HttpResponse from django.template import RequestContext, Template user = models.User.objects.get(pk=1) changed = None class TestForm(forms.Form): users = forms.ModelMultipleChoiceField(show_hidden_initial=True, queryset=models.User.objects.all()) if request.method == 'POST': form = TestForm(data=request.POST) form.is_valid() ### next line raised: TypeError int() argument must be a string or a number, not 'list' ### ### django/db/models/fields/__init__.py in get_prep_value, line 613 ### changed = form.has_changed() else: form = TestForm(initial={'users': [user]}) c = RequestContext(request, {'form': form, 'changed': changed}) t = Template(""" <form method=POST> {% csrf_token %} {{form}} <input type=submit> </form> {{changed}} """) return HttpResponse(t.render(c)) }}} if change to: users = forms.ModelMultipleChoiceField(queryset=models.User.objects.all()) and form = TestForm(data=request.POST, initial={'users': [user]}) This works, but may lead to loss of the changes made by other users -- Ticket URL: <https://code.djangoproject.com/ticket/21568> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/061.4a9cb51cb10cbe5d96f37bda059bd9b9%40djangoproject.com. For more options, visit https://groups.google.com/groups/opt_out.