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

From Collections not propagating media #197

Open
nicomarg opened this issue Jan 29, 2025 · 1 comment
Open

From Collections not propagating media #197

nicomarg opened this issue Jan 29, 2025 · 1 comment
Labels
enhancement New feature or request

Comments

@nicomarg
Copy link

Django allows the user to attach additional css/js resources to a form or a widget.
Currently, FormCollections can have a Media class to provide additional resources for themselves to use, however they don't collect the media defined in their forms (and these forms' fields by extension).

I did this not-so-dirty fix in my project (based on the media method of the django Form class), which if I understand the codebase correctly would account for nested collections if this was the media property of the FormCollection class :

@property
def media(self):
    """Return all media for forms in this collection"""
    media = Media()
    for form in self.declared_holders.values():
        media += form.media
    return media

This allows to only use {{ form_collection.media }} in the template, and not search for the collection's sub forms explicitly.

@jrief
Copy link
Owner

jrief commented Jan 29, 2025

In my projects, I actually always attempt to use the built-in or pilfered styles. But I get your point, this actually is something very useful. In my opinion however, this would be a valid use-case for a singleton available by the rendering view.

I'll need to have a deeper look, but I will find a solution. Thanks for the hint.

@jrief jrief added the enhancement New feature or request label Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants