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.
Duplicate of another ticket that reports this exact same thing (and who's number I can't recall).