5

The Error

I'm trying to use the django-nested-inline package. It seems like everything works but when I try to create a new Course with the admin website I get the following error:

TemplateDoesNotExist at /admin/courses/course/5/

admin/edit_inline/stacked-nested.html

But of course, admin/edit_inline/stacked-nested.html only doesn't exist because there was an error during template rendering:

Error during template rendering

In template C:\...\django\contrib\admin\templates\admin\change_form.html, error at line 62

admin/edit_inline/stacked-nested.html

60 {% block inline_field_sets %}
61 {% for inline_admin_formset in inline_admin_formsets %}
62     {% include inline_admin_formset.opts.template %}
63 {% endfor %}
64 {% endblock %}

As you can see, something messes up when Django tries to render

{% include inline_admin_formset.opts.template %}

My Code

Here's my admin.py, but I don't think it really has anything to do with the above error:

from django.contrib import admin
from nested_inline.admin import NestedStackedInline, NestedModelAdmin
from courses.models import Course, Skill, Note

class NoteInline(NestedStackedInline):
    model = Note
    extra = 0

class SkillInline(NestedStackedInline):
    model = Skill
    extra = 0
    inlines = [NoteInline]

class CourseAdmin(NestedModelAdmin):
    inlines = [SkillInline]

admin.site.register(Course, CourseAdmin)

And here's my models.py:

from django.db import models

class Course(models.Model):
    course_name = models.CharField(max_length=200)
    course_description = models.CharField(max_length=1000, default='Course Description')
    course_subject = models.CharField(max_length=200, default='No Subject')

    def num_skills(self):
        return len(self.skill_set.all())

    def __unicode__(self):
        return self.course_name

    def __str__(self):
        return unicode(self).encode('utf-8')

class Skill(models.Model):
    course = models.ForeignKey(Course)
    skill_name = models.CharField(max_length=200)
    skill_description = models.CharField(max_length=1000, default='Skill Description')

    def __unicode__(self):
        return self.skill_name

    def __str__(self):
        return unicode(self).encode('utf-8')

class Note(models.Model):
    skill = models.ForeignKey(Skill)
    note_text = models.CharField(max_length=1000, default='...note text...')

    def __unicode__(self):
        return self.note_text

    def __str__(self):
        return unicode(self).encode('utf-8')

Things I've Noticed

  • django-nested-inline was updated from 0.3.3 to 0.3.4 two days ago. The updated version "added licence and updated for python 3". I'm using 0.3.4, but also Python 2.7, not Python 3. However, I uninstalled 0.3.4, installed 0.3.3, and tried again. This didn't work and produced the same error. I've since uninstall 0.3.3 and reinstall 0.3.4.
  • The admin site and the site itself doesn't crash, just when I try to add a new Course via the admin site.

2 Answers2

6

It looks like your nested_inline app is not installed or django would be able to find the templates. Either that or add the templates to a directory referenced by your TEMPLATE_DIRS setting or change the template name for your inlines.

Per the usage in the link you provided: Add nested_inline to INSTALLED_APPS

ESPmorph
  • 254
  • 1
  • 3
0

Just to complete ESPmorph answer:

You need to add ALL the apps that you wish to use templates from, in the TEMPLATE_DIRS list inside project/main_app/settings.py like so:

INSTALLED_APPS = [
    'django.contrib.admin',
    ...
    "nested_inline",
]

This is indicated in django-nested-inline doc:

Usage: Add nested_inline to INSTALLED_APPS

You need to do that for all your own custom apps AND all your third party apps as well, like with django-nested-inline (add nested_inline) or django-polymorphic (add polymorphic) for instance.

Onyr
  • 769
  • 5
  • 21