Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Inlines weird behavior with django-grappelli integration #232

Closed
HaddadJoe opened this issue Jan 9, 2023 · 1 comment
Closed

Inlines weird behavior with django-grappelli integration #232

HaddadJoe opened this issue Jan 9, 2023 · 1 comment

Comments

@HaddadJoe
Copy link

HaddadJoe commented Jan 9, 2023

I'm running into some weird behavior when trying to run/integrate a multiple layer nested admin with grappelli.

Here's the original issue opened on django-grappelli

here's the dummy models I have. Nothing too fancy, pretty straightforward nested models. Note that the Article has two foreign key referencing it. One from the image and one from the paragraph models.

class TableOfContents(models.Model):
    title_tableofcontents = models.TextField()


class TocSection(models.Model):
    title_tocsection = models.TextField()
    table_of_content = models.ForeignKey(TableOfContents, on_delete=models.CASCADE)


class TocArticle(models.Model):
    title_tocarticle = models.TextField()
    section = models.ForeignKey(TocSection, on_delete=models.CASCADE)


class TocParagraph(models.Model):
    title_tocparagraph = models.TextField()
    article = models.ForeignKey(TocArticle, on_delete=models.CASCADE)


class TocImage(models.Model):
    title_tocimage = models.TextField()
    article = models.ForeignKey(TocArticle, on_delete=models.CASCADE)

Here's how my admin looks without trying to rearrange the nested inlines. Also nothing too fancy here pretty straightforward, just note that article is already an inline of sections (which is an inline of table of content)

class TocParagraphInline(NestedStackedInline):
    model = models.TocParagraph


class TocImageInline(NestedStackedInline):
    model = models.TocImage


class TocArticleInline(NestedStackedInline):
    model = models.TocArticle
    inlines = [TocParagraphInline, TocImageInline]
    fieldsets = [
        (
            "Image Data",
            {
                "fields": [],
                # "classes": [
                #     "placeholder tocsection_set-1-tocarticle_set-0-tocimage_set-group"
                # ],
            },
        ),
        (
            "Paragraph Data",
            {
                "fields": [],
                # "classes": [
                #     "placeholder tocsection_set-1-tocarticle_set-0-tocparagraph_set-group"
                # ],
            },
        ),
        (
            "Article Data",
            {"fields": ["title_tocarticle"]},
        ),
    ]


class TocSectionInline(NestedStackedInline):
    model = models.TocSection
    inlines = [TocArticleInline]


class TableOfContentsAdmin(NestedModelAdmin):
    inlines = [TocSectionInline]


admin.site.register(models.TableOfContents, TableOfContentsAdmin)

Here's how things look on the admin UI
image

Now as you might have guessed, my goal is to rearrange the inlines image and paragraph under the designated fieldsets for each category. When uncommentting the classes to try to rearrange them some weird behavior happen. here's a screenshot
image

As you can see the sections have been rearranged correctly but as a consequence:

  1. The title of the fieldset, here Image Data and Paragraph Data have disappeared.
  2. The blue tabs to un-collapse the inlines does not work on preloaded inlines
    2.1 If I add a new article the un-collapsing works but the title of the fieldset mentioned in 1) is not present either.
  3. The add Image and Paragraph buttons also stop working when the inlines are moved.

I see that django-nested-admin has good intention in supporting grappelli. Would appreciate any help or directions, happy to contribute if I can help!

django = "4.1.5"
django-nested-admin = "4.0.2"

@fdintino
Copy link
Member

django-nested-admin uses those class names to figure out the relationships between the various inlines. They are not meant to be overwritten, and in fact they cannot be. The result of your change is to make both inlines have class="tocsection_set-1-tocarticle_set-0-tocimage_set-group tocsection_set-1-tocarticle_set-0-tocparagraph_set-group", which of course will break the code that collapses inlines and formats the fieldsets.

I don't really understand what you're trying to accomplish, but if you elaborated I might be able to suggest an alternative approach.

@theatlantic theatlantic locked and limited conversation to collaborators Jul 14, 2024
@fdintino fdintino converted this issue into discussion #257 Jul 14, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants