Repository navigation
admin doesn't seem to work with intermediate join table for manytomany #808
Unanswered
bryandunbar
asked this question in
Q&A
Replies: 4 comments
|
Do you get error:
...? |
0 replies
|
This is not a bug. Django admin only works with explicit inlines on the through model, and polymorphic admin doesn’t add extra support on top of that. What to do:
|
0 replies
|
@bckohan I think this can be made into a discussion too |
0 replies
|
@bryandunbar @diogosimao This works, but you have to inherit an inline admin class for the through model from StackedPolymorphicInline: class A(PolymorphicModel):
...
class B(A):
...
class AThrough(PolymorphicModel):
...
class BThrough(AThrough): # through models can be polymorphic too!
...
class YourModel(models.Model):
m2m_field = models.ManyToManyField(A, through=AThrough, related_name="my_models", blank=True)In your admin: import polymorphic.admin.StackedPolymorphicInline, PolymorphicInlineSupportMixin
class AThroughMembership(StackedPolymorphicInline):
model = AThrough
extra = 1
class AThroughInline(StackedPolymorphicInline.Child):
...
model = AThrough
class BThroughInline(StackedPolymorphicInline.Child):
...
model = BThrough
child_inlines = (AThroughInline, BThroughInline)
@register(YourModel)
class YourModelAdmin(PolymorphicInlineSupportMixin, PolymorphicChildModelAdmin):
inlines = (AThroughMembership,)You can see a full working example in the tests added in #807 |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I have many to many that uses
throughand specifies a join table. The admin integration for Polymorphic inlines doesn't seem to function. Is this a known issue, or am I missing something?All reactions