Opened 8 years ago

Closed 7 years ago

Last modified 4 years ago

#7129 closed (fixed)

Prepend of admin_media is not working on JS

Reported by: curaloucura Owned by: nobody
Component: contrib.admin Version: newforms-admin
Severity: Keywords: nfa-blocker
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


When declaring an admin class when I declare in the inner class Media the js list of scripts with relative url, it should prepend the admin_media url but it is not working for me:


class MyClass(admin.ModelAdmin):
    list_filter = ('created','published_date','section','journalist')
    search_fields = ('headline','story')
    class Media:
        js = ['/mymedia/js/MyScript.js',
              'js/getElementsBySelector.js'] #it should be relative to media, but it has default media instead

This is what documentation says about JS section

"If you use relative URLs — URLs that don’t start with http:// or / — then the admin site will automatically prefix these links with settings.ADMIN_MEDIA_PREFIX"

Change History (10)

comment:1 Changed 8 years ago by brosner

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Can you provide a bit more information? What is the value of both MEDIA_URL and ADMIN_MEDIA_PREFIX? Also what is the exact output of the URL?

comment:2 Changed 8 years ago by curaloucura

ok, so I have the following configuration

MEDIA_URL = '/local_media/'

ADMIN_MEDIA_PREFIX = '/media/admin/'

and the following model representation for admin:

class MyClass(admin.ModelAdmin):

list_filter = ('field',)
search_fields = ('field',)

class Media:

js = ['/mymedia/js/i_am_in_any_media.js',


Usign trunk, the first js will keep untouched which is fine on both but the second one on trunk will become "/media/admin/js/i_am_in_admin.js", but usign newsforms-admin it returns the same "js/i_amin_in_admin.js" with nothing prefixed. Since the django docs says that the ADMIN_MEDIA_PREFIX will prepend relative urls, I consider this should be the same for newforms-admin

comment:3 Changed 7 years ago by Karen Tracey <kmtracey@…>

  • Keywords nfa-blocker added

Adding the ADMIN_MEDIA_PREFIX used to be done by the include_admin_script templatetag. This seems to be gone in nfa and it doesn't seem the code has been added anywhere to check for relative/absolute user-specified js and add ADMIN_MEDIA_PREFIX if necessary. Marking nfa-blocker since it's a regression from trunk.

comment:4 Changed 7 years ago by brosner

  • Resolution set to invalid
  • Status changed from new to closed

Ok, I looked into this. It appears the reporter was reading the wrong documentation. The old js inner Admin class used to do this. The correct way to use ADMIN_MEDIA_PREFIX is to add it explicitly similar to how it is done here It is a good thing it defaults to MEDIA_URL since that is the only place you should be adding your own CSS/JS. If you are needing to include something from ADMIN_MEDIA_PREFIX then there is another bug.

comment:5 Changed 7 years ago by Karen Tracey <kmtracey@…>

I'm confused. This is the doc referenced by the original submitter:

Sure, that's for old admin but I don't see any reference either here:

or here:

to the "new" way requiring that the specified js be fully-qualified.

That text has been pulled from the newforms-admin version of that doc file (the entire description of specifying js, not just the bit about what happens if it's not fully-qualified), and I can't find anyplace it's been moved to, so it's a little hard to figure out how one is supposed to migrate this bit.

Are you saying it is bad practice to add your own js in amongst the Django-supplied files and therefore this implicit support for this has been dropped in newforms-admin? If so it seems at a minimum some doc is needed somewhere to clarify that, since a straightforward migration of some old working configs apparently won't work.

comment:6 Changed 7 years ago by brosner

  • Resolution invalid deleted
  • Status changed from closed to reopened

Ok, I see where you are coming from. I will bring this up on django-dev mailing list to find out the original intensions and see if anything needs to be changed. I will reopen for now since it does seem like it will need to be addressed somehow.

comment:8 Changed 7 years ago by garcia_marc

  • milestone set to 1.0 alpha

comment:9 Changed 7 years ago by brosner

  • Resolution set to fixed
  • Status changed from reopened to closed

Ugh, Trac's post-commit hook failed again apparently. This was fixed in [7873]. I have also added a note to the page indicating the backward incompatibility with settings.ADMIN_MEDIA_PREFIX.

comment:10 Changed 4 years ago by jacob

  • milestone 1.0 alpha deleted

Milestone 1.0 alpha deleted

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