#11465: Broken representation of nonexisting objects for raw_id_fields
----------------------------------+-----------------------------------------
Reporter: [email protected] | Owner: nobody
Status: new | Milestone:
Component: django.contrib.admin | Version: SVN
Keywords: | Stage: Unreviewed
Has_patch: 0 |
----------------------------------+-----------------------------------------
In administration panel for raw_id_fields, when we manually entry id of
non-existing object, we will got TemplateSyntaxError with original
DoesNotExists exception instead of error message about non-existing
object.
Models definition:
{{{
from django.db import models
class Foo(models.Model):
name = models.CharField(max_length=10)
bar = models.ForeignKey('Bar')
class Bar(models.Model):
value = models.CharField(max_length=10)
from django.contrib.admin import ModelAdmin, site
class FooModelAdmin(ModelAdmin):
model = Foo
raw_id_fields = ('bar', )
site.register(Foo, FooModelAdmin)
site.register(Bar)
}}}
Exception after save of new Foo object with manually entered id for bar
(with empty database):
{{{
Original Traceback (most recent call last):
File "C:\Python25\lib\site-packages\django\template\debug.py", line 71,
in render_node
result = node.render(context)
File "C:\Python25\lib\site-packages\django\template\debug.py", line 87,
in render
output = force_unicode(self.filter_expression.resolve(context))
File "C:\Python25\lib\site-packages\django\utils\encoding.py", line 71,
in force_unicode
s = unicode(s)
File "C:\Python25\lib\site-packages\django\forms\forms.py", line 356, in
__unicode__
return self.as_widget()
File "C:\Python25\lib\site-packages\django\forms\forms.py", line 391, in
as_widget
return widget.render(name, data, attrs=attrs)
File "C:\Python25\lib\site-packages\django\contrib\admin\widgets.py",
line 126, in render
output.append(self.label_for_value(value))
File "C:\Python25\lib\site-packages\django\contrib\admin\widgets.py",
line 150, in label_for_value
obj = self.rel.to._default_manager.get(**{key: value})
File "C:\Python25\lib\site-packages\django\db\models\manager.py", line
120, in get
return self.get_query_set().get(*args, **kwargs)
File "C:\Python25\lib\site-packages\django\db\models\query.py", line
305, in get
% self.model._meta.object_name)
DoesNotExist: Bar matching query does not exist.
}}}
I think problem is with
''django.contrib.admin.widgets.ForeignKeyRawIdWidget.label_for_value()''
function which doesn't handle missing id of FK object.
This problem also appear for inline object edition with FK raw_id_fileds.
--
Ticket URL: <http://code.djangoproject.com/ticket/11465>
Django <http://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 post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---