ModelAdmin Media JS file order issue in Django 2.0

87 views
Skip to first unread message

Marc R

unread,
Dec 10, 2017, 9:30:38 AM12/10/17
to Django users
I have this in my model:

class Media:
        js = (
            '/static/plugins/codemirror/lib/codemirror.js',
            '/static/plugins/codemirror/mode/htmlmixed/htmlmixed.js',
            '/static/plugins/codemirror/addon/fold/foldcode.js',
            '/static/plugins/codemirror/addon/fold/foldgutter.js',
            '/static/plugins/codemirror/addon/fold/brace-fold.js',
            '/static/plugins/codemirror/addon/fold/indent-fold.js',
            '/static/plugins/codemirror/addon/fold/comment-fold.js',
            '/static/plugins/codemirror/addon/fold/xml-fold.js',
            '/static/plugins/codemirror/addon/comment/comment.js',
            '/static/plugins/codemirror/addon/edit/matchbrackets.js',
            '/static/plugins/codemirror/addon/edit/matchtags.js',
            '/static/plugins/codemirror/mode/javascript/javascript.js',
            '/static/plugins/codemirror/mode/xml/xml.js',
            '/static/plugins/codemirror/mode/htmlmixed/htmlmixed.js',
            '/static/plugins/codemirror/addon/display/fullscreen.js',
            '/static/js/admin/syslog/syslog_change_form.min.js'
        )

which used to work as it was included in the model admin page in the order it appears. However, now in Django 2.0, it appears in this order:
<script type="text/javascript" src="/static/plugins/codemirror/addon/fold/foldcode.js"></script>
<script type="text/javascript" src="/static/plugins/codemirror/addon/fold/foldgutter.js"></script>
<script type="text/javascript" src="/static/plugins/codemirror/addon/fold/brace-fold.js"></script>
<script type="text/javascript" src="/static/plugins/codemirror/addon/fold/indent-fold.js"></script>
<script type="text/javascript" src="/static/plugins/codemirror/addon/fold/comment-fold.js"></script>
<script type="text/javascript" src="/static/plugins/codemirror/addon/fold/xml-fold.js"></script>
<script type="text/javascript" src="/static/plugins/codemirror/addon/comment/comment.js"></script>
<script type="text/javascript" src="/static/plugins/codemirror/addon/edit/matchbrackets.js"></script>
<script type="text/javascript" src="/static/plugins/codemirror/addon/edit/matchtags.js"></script>
<script type="text/javascript" src="/static/plugins/codemirror/mode/javascript/javascript.js"></script>
<script type="text/javascript" src="/static/plugins/codemirror/mode/xml/xml.js"></script>
<script type="text/javascript" src="/static/plugins/codemirror/lib/codemirror.js"></script>
<script type="text/javascript" src="/static/plugins/codemirror/mode/htmlmixed/htmlmixed.js"></script>
<script type="text/javascript" src="/static/plugins/codemirror/addon/display/fullscreen.js"></script>
<script type="text/javascript" src="/static/js/admin/syslog/syslog_change_form.min.js"></script>

The issue is that the First file MUST be first as the remainder rely upon it!  I'd rather not override a template file as if i change the admin backend with a package i'd like this to "just work" as it did in Django 1.11
Is this a bug in the new way that Django includes these files (docs say they made a change in how this is done, clearly it broke something that worked!).

Thanks


Etienne Robillard

unread,
Dec 10, 2017, 9:36:56 AM12/10/17
to Marc R, django...@googlegroups.com

Why don't you simply put the javascripts into your base template without using Python ?

Etienne

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5ad93160-05c2-4251-84ad-6f8a1574b675%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

-- 
Etienne Robillard
tka...@yandex.com
https://www.isotopesoftware.ca/

Marc R

unread,
Dec 10, 2017, 9:47:56 AM12/10/17
to Django users
because they are specific to only a few models, particularly the loading scripts, and options, etc.  this worked great in Django 1.11

Andréas Kühne

unread,
Dec 10, 2017, 10:05:27 AM12/10/17
to django...@googlegroups.com
Checking through the documents I found the following reference:


Changed in Django 2.0:

In older versions, the assets of Media objects are concatenated rather than merged in a way that tries to preserve the relative ordering of the elements in each list.


I'm guessing that this is your problem. 

From what I understand in this context, the:

<script type="text/javascript" src="/static/plugins/codemirror/lib/codemirror.js"></script>

import seems to be added in a previous dependent form and therefore is not added again - you should probably check if the file is added somewhere else?

Best regards,

Andréas

To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages