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

StackedPolymorphicInline & Grappelli support #234

Open
Quantra opened this issue Aug 22, 2016 · 9 comments
Open

StackedPolymorphicInline & Grappelli support #234

Quantra opened this issue Aug 22, 2016 · 9 comments

Comments

@Quantra
Copy link
Contributor

Quantra commented Aug 22, 2016

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

@vdboor
Copy link
Collaborator

vdboor commented Aug 23, 2016

Hi! I've fixed one bug after the 1.0b1 release (4a60c1f that you now use), so if you can try 83cb059, I'd love to hear if that fixes things for you. It fixes displaying the new forms on validation errors.

@Quantra
Copy link
Contributor Author

Quantra commented Aug 23, 2016

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

@vdboor
Copy link
Collaborator

vdboor commented Aug 29, 2016

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

@vdboor
Copy link
Collaborator

vdboor commented Sep 2, 2016

I've added an explicit hiding rule to our template also works for grappelli. Does c8dd04b (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)

@Quantra
Copy link
Contributor Author

Quantra commented Sep 3, 2016

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.

@vdboor
Copy link
Collaborator

vdboor commented Sep 12, 2016

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.

@ADR-007
Copy link

ADR-007 commented Feb 5, 2020

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

@Safrone
Copy link

Safrone commented Nov 10, 2021

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
Copy link

Safrone commented Nov 10, 2021

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

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

No branches or pull requests

4 participants