Opened 8 years ago

Closed 8 years ago

#4185 closed (fixed)

error with ModelMultipleChoiceField, help_text an i18n=True

Reported by: stefan@… Owned by: adrian
Component: Forms Version: master
Severity: Keywords: USE_I18N unicode newforms ModelMultipleChoiceField
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


I have a Model:

class Project(models.Model):
	name = models.CharField(maxlength=200)
	long_name = models.CharField(maxlength=512)
	company = models.ForeignKey(Company)
	employee = models.ManyToManyField(Employee)
	def __str__(self):
		return "%s (%s)" % (,
	class Admin:
		list_display = ('name','long_name','company')
	class Meta:
		verbose_name = 'Project'
		verbose_name_plural = 'Projects'
		unique_together = (('name','company'),)

a View-Function:

def edit_project(request,name, id):
	project = get_object_or_404(Project,pk=id)
	ProjectForm = forms.models.form_for_instance(project)
	if request.POST:
		myform = ProjectForm(request.POST)
		if myform.is_valid():
		myform = ProjectForm()
	return render_to_response('timer/edit_project.html',{'myform':myform},context_instance=RequestContext(request))

and a Template:

{% extends "index.html" %}

{% block content %}

{{ myform.as_p }}

{% endblock %}
  • If I set USE_I18N=True in, that happens:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/template/" in render_node
  732. result = node.render(context)
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/template/" in render
  782. output = self.filter_expression.resolve(context)
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/template/" in resolve
  572. obj = resolve_variable(self.var, context)
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/template/" in resolve_variable
  665. current = current()
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/newforms/" in as_p
  160. return self._html_output(u'<p>%(label)s %(field)s%(help_text)s</p>', u'<p>%s</p>', '</p>', u' %s', True)
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/newforms/" in _html_output
  134. help_text = help_text_html % field.help_text

  UnicodeDecodeError at /timer/stefan/projects/4/
  'ascii' codec can't decode byte 0xc3 in position 93: ordinal not in range(128)
  • If I set USE_I18N=False, everything works fine.
  • If I set USE_I18N=True and comment out the employee field in the Project Model everything works fine.

My Browser uses German as the standard locale.
Looks like there's an error with the help_text of the ModelMultipleChoiceField

Change History (2)

comment:1 Changed 8 years ago by Simon G. <dev@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Hi Stefan, can you try this on the unicode branch - all these ascii decode issues should be gone from there.

comment:2 Changed 8 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to closed

Fixed in [5609].

Note: See TracTickets for help on using tickets.
Back to Top