Opened 18 years ago
Closed 18 years ago
#4185 closed (fixed)
error with ModelMultipleChoiceField, help_text an i18n=True
| Reported by: | Owned by: | Adrian Holovaty | |
|---|---|---|---|
| Component: | Forms | Version: | dev |
| 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: | no | UI/UX: | no |
Description
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)" % (self.name, self.company)
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.save()
else:
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 settings.py, that happens:
Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/template/__init__.py" in render_node 732. result = node.render(context) File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/template/__init__.py" in render 782. output = self.filter_expression.resolve(context) File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/template/__init__.py" in resolve 572. obj = resolve_variable(self.var, context) File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/template/__init__.py" in resolve_variable 665. current = current() File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/newforms/forms.py" 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/forms.py" 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
Note:
See TracTickets
for help on using tickets.
Hi Stefan, can you try this on the unicode branch - all these ascii decode issues should be gone from there.