django-polymorphic
django-polymorphic copied to clipboard
StackedPolymorphicInline & Grappelli support
Hi I'm using commit #4a60c1f so apologies if this is on its way and thank you to everyone contributing to this project.
Currently when using Grappelli with polymorphic I can use StackedPolymorphicInline to create the inline as per the docs but it does not render correctly in the admin site.
It appears the blank dummy forms are being displayed and validated on submission and new forms are added in a strange way.
Also Grappelli's drag and drop reordering through sortable_field_name doesn't appear compatible. It would be amazing to have this working with an order field on the parent model.
I've attached a couple of screenshots showing the StackedPolymorphicInline when adding a new object and after adding a child field.
class ContentBlockInline(StackedPolymorphicInline):
class WYSIWYGBlockInline(StackedPolymorphicInline.Child):
model = WYSIWYGBlock
class HeroBlockInline(StackedPolymorphicInline.Child):
model = HeroBlock
model = ContentBlock
child_inlines = (WYSIWYGBlockInline, HeroBlockInline)
extra = 0
min_num = 0
sortable_field_name = 'order'
Hi! I've fixed one bug after the 1.0b1 release (4a60c1fb60fe854a435227ac793d0bbe2bf7f61e that you now use), so if you can try 83cb059317dd5492ed32b8f95cbccde1d32a7119, I'd love to hear if that fixes things for you. It fixes displaying the new forms on validation errors.
@vdboor now using 83cb059 and the behaviour with Grappelli is the same as I describe above.
If I find a moment I will likely try django-polymorphic with other packages which provide drag and drop ordering of inlines as this is the functionality I really desire. I can report back on them if it is of interest.
What CSS class does Grapelli use to hide the empty template forms?
I've added an explicit hiding rule to our template also works for grappelli. Does c8dd04bba0052f2a3a9536d2bf0944ef9ceb068b (and v1.0) work for you?
(grappelli uses .grp-empty-form instead of .empty-form. I'm a bit confused why they diverted from the standard CSS class name everyone else uses)
Thank you. This does hide the dummy forms and provide some compatibility with Grappelli. It doesn't work with the drag and drop reordering. I did look into merging the polymorphic inline template with the Grappelli one to enable this but I had little success.
There is a small CSS tweak required for v1 when using Grappelli. I'll make a PR for it shortly.
You're welcome! Glad to know it works.
If you like to create the template, notice that the main difference from the standard template are:
- the extra data attibutes
- the hidden polymophic_ctype field
- the check on
__prefix__instead offorloop.lastto show the empty form.
This might help to reconstruct a grapelli template that works with polymorphic inlines.
Hi! I have the same problem. Do you have some progress with this?
I have the same issue, It would be nice if it used the same general bounding box as regular inlines:
here is a regular inline followed by a polymorphic inline
just adding grp-module makes the display a fair bit nicer

this can be done by adding classes = ['grp-module'] to the StackedPolymorphicInline subclass:
