Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for generic inlines #7

Open
BertrandBordage opened this issue May 6, 2013 · 5 comments
Open

Support for generic inlines #7

BertrandBordage opened this issue May 6, 2013 · 5 comments

Comments

@BertrandBordage
Copy link

Currently, mixing Nested(Stacked|Tabular)Admin with Generic(Stacked|Tabular)Admin is not working.

IMO, this is a critical feature.

@boylesnick
Copy link

Has anyone been able to find a good workaround for this issue?

@BertrandBordage
Copy link
Author

Not me, unfortunately...

@RRMoelker
Copy link

I have not tried out a generic nested inline, however I do use a generic inline with a NestedModelAdmin at the moment. I kept getting an error, but the solution was very simple. All I needed to do was add inlines = [] to the generic admin inline.

So the following will only work with a generic inline that is an end point (does not have inlines of it's own)! So this is not a true generic nested inline, but I'm able to help someone.

Say you have a model:

class A(models.Model):
    pass
    d_objects = generic.GenericRelation('D')

class B(models.Model):
    parent = models.ForeignKey(A)

class C(models.Model):
    parent = models.ForeignKey(B)

class D(models.Model):
    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField()
    content_object = generic.GenericForeignKey('content_type', 'object_id')

So A is our root object. A has B as children which has C as children. For this argument D has only A as a foreign relation.

Admin.py:

from django.contrib import admin
from django.contrib.contenttypes import generic
from nested_inlines.admin import NestedModelAdmin, NestedTabularInline, NestedStackedInline

class C_Inline(NestedStackedInline):
    model = C

class B_Inline(NestedStackedInline):
    model = B
    inlines = [C_Inline]

class D_Inline(generic.GenericStackedInline):
    model = D
    inlines = [] # THIS IS THE FIX

class A_Admin(NestedModelAdmin):
    inlines = [B_inline, D_inline, ]
admin.site.register(A, A_Admin)

Possible all that is needed to get nested inlines to work with generic keys is adding:
ct_field = "content_type"
ct_fk_field = "object_id"
To a "NestedStackedInline". But my setup doesn't require this, so I haven't tested it at the moment.

@brmc
Copy link

brmc commented Apr 14, 2015

@BertrandBordage
Copy link
Author

@brmc Hi! Thanks for sharing. Nice coincidence, I’m currently working on my own complete rewrite of inlines to handle limitless nested inlines: https://github.com/BertrandBordage/django-super-inlines. I got a first awesome result 5 minutes ago :) I also found a bunch of bugs in the inlines. It was so poorly coded…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants