Opened 12 years ago

Closed 12 years ago

#19065 closed Cleanup/optimization (needsinfo)

The FilteredManyToMany widget needs javascript in 'stacked.html' and 'tabular.html' when using inline content

Reported by: replytosander@… Owned by: nobody
Component: contrib.admin Version: 1.4
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I'm developing a custom sortable manytomany widget which allows the user to order the items in the widget.

You can find it here: https://github.com/fabrique/django-sortedm2m

When using inline models the widget needs the javascript in stacked.html and/or tabular.html. It initializes a new instance when adding an inline item.

To keep the sortedm2m library as pluggable as possible I would like to know how I can provide this javascript in the library. This way a developer doesn't need to override the admin templates.

This doesn't seem possible at the moment. Maybe there should be a way to provide document ready javascript in the scope of the widget.

Any ideas on this?

Change History (2)

comment:1 by anonymous, 12 years ago

Code used in overridden stacked.html template:

var updateOrderedSelectFilter = function() {
            // If any SelectFilter widgets are a part of the new form,
            // instantiate a new SelectFilter instance for it.
            if (typeof OrderdSelectFilter != "undefined"){
                $(".selectfilter").each(function(index, value){
                    var namearr = value.name.split('-');
                    OrderdSelectFilter.init(value.id, namearr[namearr.length-1], false, "{% admin_media_prefix %}");
                });
                $(".selectfilterstacked").each(function(index, value){
                    var namearr = value.name.split('-');
                    OrderdSelectFilter.init(value.id, namearr[namearr.length-1], true, "{% admin_media_prefix %}");
                });
            }
        }

comment:2 by Aymeric Augustin, 12 years ago

Resolution: needsinfo
Status: newclosed

This is a feature request, and it isn't very precise. In such cases, it's best to write to the django-developers mailing list, and open a ticket once a concrete action plan has been determined.

Overriding admin templates is the canonical way to inject additional features in the admin pages. Your library can ship templates replacing the admin's built-in templates; they will be used if you app comes before django.contrib.admin in INSTALLED_APPS.

Note: See TracTickets for help on using tickets.
Back to Top