Inconsistency between django.contrib.admin.models.LogEntry interface and index.html admin template
This inconsistency lies in fact that LogEntry
model allows for content_type
(and object_id
) to be None
(both attributes are defined as blank=True, null=True
). This causes admin index page failing to render in line 62 of index.html template, which implicitly requires content type to be set: {% filter capfirst %}{% trans entry.content_type.name %}{% endfilter %}
.
Caught an exception while rendering: Failed lookup for key [name] in u'None'
Original Traceback (most recent call last):
File "/usr/lib/python2.5/site-packages/django/template/debug.py", line 71, in render_node
result = node.render(context)
File "/usr/lib/python2.5/site-packages/django/templatetags/i18n.py", line 42, in render
value = self.value.resolve(context)
File "/usr/lib/python2.5/site-packages/django/template/__init__.py", line 676, in resolve
value = self._resolve_lookup(context)
File "/usr/lib/python2.5/site-packages/django/template/__init__.py", line 729, in _resolve_lookup
raise VariableDoesNotExist("Failed lookup for key [%s] in %r", (bit, current)) # missing attribute
VariableDoesNotExist: Failed lookup for key [name] in u'None'
Ok. I've changed the template and wrap the
entry.content_type.name
by first doing a{% if entry.content_type %}
so now it's no longer inconsistent.I've also change the template to not be all on one line but instead multiple lines and indented.
If the HTML has to be completely without whitespace (clearly not a problem in Firefox) it should be wrapped with a spaceless filter or a comment that explains why it can not have whitespace in it.
Attached is a patch plus a patch to the tests which feels a bit bloated but works.