Skip to content

From Collections not propagating media #197

@nicomarg

Description

@nicomarg

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions