admin doesn't seem to work with intermediate join table for manytomany #808
Replies: 4 comments
-
|
Do you get error:
...? |
Beta Was this translation helpful? Give feedback.
-
|
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:
|
Beta Was this translation helpful? Give feedback.
-
|
@bckohan I think this can be made into a discussion too |
Beta Was this translation helpful? Give feedback.
-
|
@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 |
Beta Was this translation helpful? Give feedback.
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?Beta Was this translation helpful? Give feedback.
All reactions