I've got a custom user model, with ManyToManyField called
'favorite_bands'.
I'd like to use [http://ivaynberg.github.io/select2/] widget.
This includes some js files, but I need to include a jquery library higher
than 1.4.
If I user the MEDIA class
[https://docs.djangoproject.com/en/dev/ref/contrib/admin/#modeladmin-
asset-definitions], this do not ensure me the needed order (first
jquery.1.10, then anothers).
I've done this: [http://stackoverflow.com/questions/1164358/django-admin-
custom-javascript-load-order]
Can you add a 'pre_media' var in AdminModel to set a user ordered list of
js and render them before 'media' var? Or add it to MEDIA class?
That could be a solution.
This is the relevant part of code
{{{
{% block extrahead %}{{ block.super }}
<script type="text/javascript" src="{% url 'admin:jsi18n' %}"></script>
<script type="text/javascript" src="{{ STATIC_URL
}}js/jquery/jquery-1.10.1.js"></script>
{# I've inserted the jquery version, I'd like to have a var 'pre_media'
var here #}
{{ media }}
{% endblock %}
}}}
{{{
class UserChangeForm(forms.ModelForm):
class Meta:
model = get_user_model()
widgets = {
'favorite_bands': HeavySelect2MultipleWidget(
data_view='search_bands', select2_options={
'width': 600,
'closeOnSelect': True
}),
}
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/21318>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
Personally, my feeling is that you need to override the template of you
want to do something clever like this. I don't think this is a helpful
feature to add.
I'm also a little confused why you're trying to insert a different jquery
- the admin in 1.5.x uses jq 1.10 which is newer than 1.4 - so select2
should work fine.
--
Ticket URL: <https://code.djangoproject.com/ticket/21318#comment:1>
Comment (by timo):
Marc, I'm not sure if you're correct re: the version of jQuery the Django
includes. [https://docs.djangoproject.com/en/dev/ref/contrib/admin/#jquery
According to the docs]: "Changed in Django 1.6: The embedded jQuery has
been upgraded from 1.4.2 to 1.9.1."
However, I agree that overriding the template is probably the way to go
here, unless there's a very clean way to do this in code. I don't think we
should bent over backwards to meet this use case.
--
Ticket URL: <https://code.djangoproject.com/ticket/21318#comment:2>
Comment (by lalo):
Yes? overriding the template? copying and pasting all these code?
I don't belive so.
What I'd like it's a way to ensure the order in the js.
In this case I need jquery before select2 libraries, but if want to
include another after or before(maybe a internationalization library, how
do it?
maybe the ModelAdmin.MEDIA precedes the Form.MEDIAs or Widget.MEDIA, I
think.
--
Ticket URL: <https://code.djangoproject.com/ticket/21318#comment:3>
* component: contrib.admin => Documentation
* stage: Unreviewed => Accepted
* type: New feature => Cleanup/optimization
* version: 1.5 => master
Comment:
I haven't used `Media` very much, but it seems like what you are trying to
do should be possible without additional features. There must be a defined
order in how the various `Media` classes you described are combined and
output. Perhaps we can improve our documentation in this area.
--
Ticket URL: <https://code.djangoproject.com/ticket/21318#comment:4>
Comment (by lalo):
Ok, if you can ensure the Media order, this could be the solution. But
now, there isn't documentation or a clear way to do it.
Thank for you time.
--
Ticket URL: <https://code.djangoproject.com/ticket/21318#comment:5>
Comment (by jpotterm):
When rendering a form, the Media classes seem to be rendered to the
template in the order of the fields they are attached to. I couldn't find
this documented anywhere (maybe it should be) but at least in the admin
interface this seems to be the case.
This doesn't really help you order them because you don't usually want to
change the order of your fields but at least it's a start to know how
things will be ordered.
--
Ticket URL: <https://code.djangoproject.com/ticket/21318#comment:6>
Comment (by timgraham):
See also #12265, "Media (js/css) collection strategy in Forms has no order
dependence concept".
--
Ticket URL: <https://code.djangoproject.com/ticket/21318#comment:7>
* status: new => closed
* resolution: => duplicate
Comment:
I believe this is fixed by #28377
--
Ticket URL: <https://code.djangoproject.com/ticket/21318#comment:8>