django nested_inlines not shown in admin site

548 views Asked by At

I'm trying to use nested_inlines and read that the bug, that the third inline is not shown was already fixed. But still I have the same problems. I'm using django 1.6.5 and python 2.7.5. The nested_inlines I downloaded from https://pypi.python.org/pypi/django-nested-inlines .

I tried the examples in the internet and put 'nested_inlines' into the INSTALLED_APPS, but I don't see the third line in my admin site.

Here my code in models.py:

from django.db import models

class A(models.Model):
    name = models.CharField(max_length = 200)

class B(models.Model):
    name = models.CharField(max_length = 200)
    fk_a = models.ForeignKey('A')

class C(models.Model):
    name = models.CharField(max_length = 200)
    fk_b = models.ForeignKey('B')

admin.py:

from django.contrib import admin
from .models import A,B,C
from nested_inlines.admin import NestedStackedInline, NestedModelAdmin

class cInline (NestedStackedInline):
    model = C

class bInline(NestedStackedInline):
    model = B
    inlines = [cInline,]
    extra = 1

class aAdmin(NestedModelAdmin):
    inlines =[bInline,]

admin.site.register(A, aAdmin)

What did I forgot? Any advices?

2

There are 2 answers

2
skzryzg On

I believe it is a bug. Im working on the exact same problem right now. Try adding an extra to cInline:

 class cInline (NestedStackedInline):
     model = C
     extra = 1

It just doesn't seem to show up when there are no related models.

edit: also, use this repo instead: https://github.com/silverfix/django-nested-inlines

They recommend it here (at the bottom): https://code.djangoproject.com/ticket/9025

installation: pip install -e git+git://github.com/silverfix/django-nested-inlines.git#egg=django-nested-inlines

0
kiwi541 On

Finally I know why it does not work!! It didn't depend on the different packages from soaa or silverfix. When I installed it with pip the package was insite PythonXX/Lib/site-packages, but somehow django wasn't able to use the package without throwing errors. So either set the system path to site-packages or copy the nested_inlines folder into Lib.