[Django] #21318: Insert jquery before another js libraries.

44 views
Skip to first unread message

Django

unread,
Oct 24, 2013, 10:33:00 AM10/24/13
to django-...@googlegroups.com
#21318: Insert jquery before another js libraries.
--------------------------------+-------------------------------
Reporter: leandro.gz73@… | Owner: nobody
Type: New feature | Status: new
Component: contrib.admin | Version: 1.5
Severity: Normal | Keywords: admin, js, jquery
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+-------------------------------
I'm using django 1.5.4

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.

Django

unread,
Oct 24, 2013, 1:00:31 PM10/24/13
to django-...@googlegroups.com
#21318: Insert jquery before another js libraries.
-----------------------------------+--------------------------------------

Reporter: leandro.gz73@… | Owner: nobody
Type: New feature | Status: new
Component: contrib.admin | Version: 1.5
Severity: Normal | Resolution:

Keywords: admin, js, jquery | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Changes (by mjtamlyn):

* 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>

Django

unread,
Oct 24, 2013, 1:09:21 PM10/24/13
to django-...@googlegroups.com
#21318: Insert jquery before another js libraries.
-----------------------------------+--------------------------------------

Reporter: leandro.gz73@… | Owner: nobody
Type: New feature | Status: new
Component: contrib.admin | Version: 1.5
Severity: Normal | Resolution:

Keywords: admin, js, jquery | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------

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>

Django

unread,
Oct 24, 2013, 3:43:33 PM10/24/13
to django-...@googlegroups.com
#21318: Insert jquery before another js libraries.
-----------------------------------+--------------------------------------

Reporter: leandro.gz73@… | Owner: nobody
Type: New feature | Status: new
Component: contrib.admin | Version: 1.5
Severity: Normal | Resolution:

Keywords: admin, js, jquery | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------

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>

Django

unread,
Oct 25, 2013, 8:30:23 PM10/25/13
to django-...@googlegroups.com
#21318: Clarify the ordering of the various Media classes
--------------------------------------+------------------------------------
Reporter: leandro.gz73@… | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: master
Severity: Normal | Resolution:
Keywords: admin, js, jquery | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timo):

* 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>

Django

unread,
Oct 25, 2013, 10:30:31 PM10/25/13
to django-...@googlegroups.com
#21318: Clarify the ordering of the various Media classes
--------------------------------------+------------------------------------
Reporter: leandro.gz73@… | Owner: nobody

Type: Cleanup/optimization | Status: new
Component: Documentation | Version: master
Severity: Normal | Resolution:
Keywords: admin, js, jquery | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

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>

Django

unread,
Jan 9, 2015, 6:05:57 PM1/9/15
to django-...@googlegroups.com
#21318: Clarify the ordering of the various Media classes
--------------------------------------+------------------------------------
Reporter: leandro.gz73@… | Owner: nobody

Type: Cleanup/optimization | Status: new
Component: Documentation | Version: master
Severity: Normal | Resolution:
Keywords: admin, js, jquery | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

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>

Django

unread,
Oct 9, 2015, 8:04:05 PM10/9/15
to django-...@googlegroups.com
#21318: Clarify the ordering of the various Media classes
--------------------------------------+------------------------------------
Reporter: leandro.gz73@… | Owner: nobody

Type: Cleanup/optimization | Status: new
Component: Documentation | Version: master
Severity: Normal | Resolution:
Keywords: admin, js, jquery | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

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>

Django

unread,
Aug 26, 2017, 9:39:52 AM8/26/17
to django-...@googlegroups.com
#21318: Clarify the ordering of the various Media classes
-------------------------------------+-------------------------------------
Reporter: leandro.gz73@… | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Documentation | Version: master
Severity: Normal | Resolution: duplicate

Keywords: admin, js, jquery | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Collin Anderson):

* status: new => closed
* resolution: => duplicate


Comment:

I believe this is fixed by #28377

--
Ticket URL: <https://code.djangoproject.com/ticket/21318#comment:8>

Reply all
Reply to author
Forward
0 new messages