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

feat: fieldsets as tabs #248

Closed
wants to merge 3 commits into from

Conversation

nabonham
Copy link

@nabonham nabonham commented Jan 4, 2024

Original issue: #44

Here is my approach to this feature. Tried my best on doing this in a non-intrusive way. Use fieldsets_tabs to create the tabs, and set fieldset-tab fieldset-tab-<tabname> in Inline and ModelAdmin classes parameter, as in the example below:

class TestModelInline(TabularInline):
    model = InlineModel
    classes = ["fieldset-tab fieldset-tab-advanced"]

@admin.register(TestModel)
class TestModelAdmin(ModelAdmin):
    fieldsets_tabs = (("general", _("General")), ("advanced", _("Advanced Settings")))
    fieldsets = [
        (
            None,
            {
                "classes": ["fieldset-tab fieldset-tab-general"],
                "description": "A very short description",
                "fields": ["field1", "field2"],
            },
        ),
        (
            _("Named Fieldset"),
            {
                "classes": ["fieldset-tab fieldset-tab-advanced"],
                "fields": ["field3", "field4"],
            },
        ),
    ]
    inlines = [
        TestModelInline
    ]

example-feat-fieldsets-tabs

@nabonham
Copy link
Author

nabonham commented Jan 4, 2024

I forgot to compile the assets before commiting & PR.

@lukasvinclav
Copy link
Contributor

lukasvinclav commented Jan 6, 2024

First of all thank you very much for your PR. I was already thinking for some time how to do it and your code forced me to do it. Below you can check my PR and let me know what you think. In general, I used alpine.js and I tried to avoid adding new attributes for tab configuration.

#249

@nabonham
Copy link
Author

nabonham commented Jan 6, 2024

First of all thank you very much for your PR. I was already thinking for some time how to do it and your code forced me to do it. Below you can check my PR and let me know what you think. In general, I used alpine.js and I tried to avoid adding new attributes for tab configuration.

#249

Hello Lukas, firstly, congratulations on the project. I hope I can continue contributing more frequently.

My approach was simplistic, and I based purely on the django-suit implementation that @minholi commented on in the issue, including using the jQuery instance available in django-admin.

I really liked your approach, especially the use of alpine.js. My only suggestion is to keep the functionality of the fieldset headers (when providing the name for them). In this case, if you want to not display the header, just pass None. In your implementation, if it has the tab class, it automatically discards the rendering of the header.

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

Successfully merging this pull request may close these issues.

2 participants