django-polymorphic icon indicating copy to clipboard operation
django-polymorphic copied to clipboard

StackedPolymorphicInline & Grappelli support

Open Quantra opened this issue 9 years ago • 9 comments

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'
screen shot 2016-08-22 at 21 17 02 screen shot 2016-08-22 at 21 21 42

Quantra avatar Aug 22 '16 20:08 Quantra

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 avatar Aug 23 '16 07:08 vdboor

@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.

Quantra avatar Aug 23 '16 12:08 Quantra

What CSS class does Grapelli use to hide the empty template forms?

vdboor avatar Aug 29 '16 12:08 vdboor

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)

vdboor avatar Sep 02 '16 10:09 vdboor

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.

Quantra avatar Sep 03 '16 14:09 Quantra

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 of forloop.last to show the empty form.

This might help to reconstruct a grapelli template that works with polymorphic inlines.

vdboor avatar Sep 12 '16 07:09 vdboor

Hi! I have the same problem. Do you have some progress with this?

ADR-007 avatar Feb 05 '20 20:02 ADR-007

I have the same issue, It would be nice if it used the same general bounding box as regular inlines:

image here is a regular inline followed by a polymorphic inline

Safrone avatar Nov 10 '21 20:11 Safrone

just adding grp-module makes the display a fair bit nicer

image

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

Safrone avatar Nov 10 '21 21:11 Safrone