I'm using some Staked and Tabular Inline with a custom template.
class AppointmentInline(InlineAutocompleteAdmin):
model = Appointment
extra = 0
template = 'my/non/existent/template/tabular.html'
When the template i'm specifying doesn't exists, the inlines doesn't show up in the admin change_form (no error is produced even in DEBUG mode): this way when i post the form data to save the model, i always get an error:
ValidationError at /admin/test/event/1/
Request Method: POST
Request URL: http://127.0.0.1:8000/admin/test/event/1/
Django Version: 1.2 beta 1
Exception Type: ValidationError
Exception Value:
Exception Location: .../thirdparty/django-1.2/django/forms/formsets.py in _management_form, line 57
Python Executable: /usr/bin/python2.6
Python Version: 2.6.2
Python Path: [...]
Server time: Tue, 25 May 2010 10:39:10 +0200
...
../thirdparty/django-1.2/django/forms/formsets.py in _management_form
50. return self.as_table()
51.
52. def _management_form(self):
53. """Returns the ManagementForm instance for this FormSet."""
54. if self.data or self.files:
55. form = ManagementForm(self.data, auto_id=self.auto_id, prefix=self.prefix)
56. if not form.is_valid():
57. raise ValidationError('ManagementForm data is missing or has been tampered with') ...
58. else:
59. form = ManagementForm(auto_id=self.auto_id, prefix=self.prefix, initial={
60. TOTAL_FORM_COUNT: self.total_form_count(),
61. INITIAL_FORM_COUNT: self.initial_form_count(),
62. MAX_NUM_FORM_COUNT: self.max_num
63. })
I think when resolving the template of an inline, django should at least report with an error that the specified template doesn't exists.
This problem exists because Django's template language silently eats errors, so the call to {% include inline_admin.opts.template %} fails silently if the template doesn't exist.
The solution here is to validate that the template exists when the InlineModelAdmin object is validated -- see django.contrib.admin.validation.validate_inline.