sehmaschine / django-grappelli

A jazzy skin for the Django Admin-Interface (official repository).
http://www.grappelliproject.com
Other
3.73k stars 659 forks source link

Filter functionality on admin pages don't work unless actions = None on ModelAdmins #214

Closed karansag closed 2 years ago

karansag commented 11 years ago

Hi all,

Unless actions = None in my ModelAdmin class definitions, grappelli raises and javascript exception and the filter functionality (with fields defined in list_filter) breaks. The dropdown button shows up but nothing drops down when you click on it.

The error is "Uncaught TypeError: Object [object Object] has no method 'actions' " on the line $("tr input.action-select").actions(); (line 66 in the grappelli template).

The relevant code snippet from the grappelli code

Also, I think this might be similar to Issue #206.

I'm using Django 1.4.1 and Grappelli 2.4.2

sehmaschine commented 11 years ago

Are you sure you´ve cleared the cache and you´re loading the right files? because I´m not able to reproduce this (and I´m pretty sure this bug doesn´t exist).

sehmaschine commented 11 years ago

I´ve checked again and I´m not able to reproduce this ... please re–open the ticket if you think it´s a bug.

karansag commented 11 years ago

You're right--it must have been a cache issue, because it's gone now. Strange thing is that I'm using a development server (Werkzeug) and didn't set any cache headers. I've never had a problem with Chrome auto-caching something before. Is something different about Grappelli's dynamically generated content? If so, could we put some kind of notice in for others? It looks like it's happened before (see Issue #206, mentioned above).

philwo commented 11 years ago

I stumbled upon this, too and it doesn't look like a cache issue to me. Even if I delete the cache in Chrome and Firefox and revisit the admin site, the error doesn't disappear. Also, restarting the Django server (I'm using gunicorn) doesn't help. I didn't do any configuration of grappelli yet, just installed it via pip (django-grappelli==2.4.2) and included it in the INSTALLED_APPS in settings.py (before django.contrib.admin).

The problem, I think, is, that the failing call to ".actions()" uses grp.jQuery, but .action() is only defined in django.jQuery. In grappelli.min.js you seem to try to set django.jQuery to grp.jQuery, so that they're the same, but because the grappelli scripts are loaded before the Django admin JavaScripts, that doesn't work.

This is what the HTML code of a Django admin list overview page looks like in my case:

<!-- jQuery, jQuery-UI -->
<script src="/static/grappelli/jquery/jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="/static/grappelli/jquery/ui/js/jquery-ui-1.8.18.custom.min.js" type="text/javascript"></script>

<!-- Grappelli Minified -->
<script src="/static/grappelli/js/grappelli.min.js" type="text/javascript"></script>

<script type="text/javascript" src="/static/admin/js/core.js"></script>
<script type="text/javascript" src="/static/admin/js/admin/RelatedObjectLookups.js"></script>
<script type="text/javascript" src="/static/admin/js/jquery.js"></script>
<script type="text/javascript" src="/static/admin/js/jquery.init.js"></script>
<script type="text/javascript" src="/static/admin/js/actions.js"></script>

<script type="text/javascript" src="/admin/jsi18n/"></script>

<script type="text/javascript" charset="utf-8">
    (function($) {
        $(document).ready(function() {
            $("tr input.action-select").actions();
        });
    })(grp.jQuery);
</script>

This may well be a configuration error on my side, but to me it doesn't look like a caching issue...

philwo commented 11 years ago

OK, I think I found the reason and it looks like a Django bug: When you use the static file development view of Django to serve your static files, Django doesn't serve grappelli's overridden jquery.js and jquery.init.js, but instead the original files from the Django admin, which causes this error. :( Now I'm serving my static files with nginx even during development and it works fine.

sehmaschine commented 11 years ago

I´m using staticpatterns, but I´m still not able to reproduce this.

@philwo you´re saying that grappellis jquery.js doesn´t get loaded. if that´s the case, there´s a lot of functionality which doesn´t work, right (e.g. autocompletes)? basically, not much of the admin will work as expected ...

philwo commented 11 years ago

@sehmaschine Yes, that was the case, the features relying on JavaScript didn't work. I'll try to find the cause for this problem on my configuration in the next days and will get back to you.

philwo commented 11 years ago

This is extremely strange.

I'm able to reproduce it when I run the Django devserver using "./manage.py runserver" or gunicorn using "./manage.py run_gunicorn" - then Django seems to override my whole static files config with defaults (even if I configure it totally wrong on purpose and specify non-existing classes in settings.STATICFILES_FINDERS it will still serve static files).

If I run gunicorn using "gunicorn myapp.wsgi:application", Django uses my settings correctly and I have to add the usual "urlpatterns += staticfiles_urlpatterns()" to my urls.py to get static files working. Then the override works and grappelli's JS files get served correctly instead of the original Django admin files.

I'm going to create a minimal example and if I'm successful, I'll report this as an issue on code.djangoproject.com.

sehmaschine commented 11 years ago

since we´re about to do a new release, it´d be nice to solve this issue ...

  1. it seems that STATICFILES_FINDERS is not being used with runserver (I´m able to reproduce that).
  2. still, I´m not able to get django override the grappelli files (unless I´m adding "django.contrib.admin" before "grappelli" with INSTALLED_APPS).

any additional information is helpful ... thx.

npardington commented 11 years ago

I'm having this same problem. I'm running Django 1.4.1 and have grappelli in installed apps before contrib.admin.

<script type="text/javascript" charset="utf-8">
        (function($) {
            $(document).ready(function() {
                $("tr input.action-select").actions();
            });
        })(grp.jQuery);
</script>

When I edit change_list.html to pass in django.jQuery the filter list works as you'd expect. Not a great fix but hope if provides some insight.

<script type="text/javascript" charset="utf-8">
        (function($) {
            $(document).ready(function() {
                $("tr input.action-select").actions();
            });
        })(django.jQuery);
</script>
maffacow commented 11 years ago

I am also having this issue running Django 1.4.2 and Grappelli 2.4.3 on a fresh install of Ubuntu 10.04

$("tr input.action-select").actions is not a function

is the error being shown with firebug.

The filter doesn't work and I cant select items for deletion.

I have tried using the domain name directly and also with runserver.

At first I was getting the error with both but changing

STATIC_URL = 'http://somedomain.com/static/'

to simply

STATIC_URL = '/static/'

fixed the issue when using runserver but the problem still exists when using the domain name.

I have compared the html output code of both and they are identical.

It all works flawlessly on my dev server and I would just like to say a big thanks for a fantastic product. Fingers crossed a fix can be found for this.

Any further info I can supply you with please just ask.

maffacow commented 11 years ago

Has there been any progress with this issue?

I have two sites to put live for clients and I will need to do some recoding if I have to revert back to the Django templates.

sehmaschine commented 11 years ago

@maffacow since I´ve never been able to reproduce this issue, I need to rely on feedback. so far, I´m not sure what a "fix" could be ...

maffacow commented 11 years ago

Since the website is not yet live, I can give you ssh access if you require? Or is there any info I can provide you with?

sehmaschine commented 11 years ago

well ... you can debug, find the issue (if it actually exists) and submit a pull–request. that´s the most straightforward way to solve it.

tangent commented 11 years ago

I am having the same/similar issue, site works fine on devserver but JS loading seems to be not working properly on production server (nginix)

Django's default jquery libs are being loaded rather than the grappelli overrides

The only place grappelli javascripts are working is on the main admin/ page, ie the click() event is handled for the user options dropdown when you click on the username in the top menu.. but only if you are on the main admin dashboard. (because django does not load its jquery libraries on the main admin dashboard)

Django 1.4.2 with Grappelli 2.4.3, no caching enabled, everything appears to be configured properly.. have numerous Django 1.3 sites with grappelli on similar production setup with no issues.

maffacow commented 11 years ago

Ok, I finally got this working on my system.

Sehmaschine, is correct in my instance, it wasnt actually a bug but more to do with my settings.

I was loading the static files from the dist-packages using apache in my sites-available file.

Alias /static/grappelli /usr/local/lib/python2.6/dist-packages/grappelli/static/grappelli Alias /static /usr/local/lib/python2.6/dist-packages/Django-1.4-py2.6.egg/django/contrib/admin/static

This was stupid I know, but the way I was shown when first introduced to Django

All I needed to have was Alias /static /srv/www/mywebsite.com/public_html/static

and in my settings.py STATIC_ROOT = '/srv/www/mywebsite.com/public_html/static/' STATIC_URL = '/static/'

I hope this may be of some help to others and once again, thank you for such a great script

tangent commented 11 years ago

OK I figured out my issue also, it was indeed a caching/configuration error.

Caching was disabled for HTTP but enabled for SSL /static alias.

mborho commented 11 years ago

I had a similar configuration like maffacow.

Using the collectstatic command and removing the alias for the admin files in the server-configuration fixed the issue for me.

pombredanne commented 11 years ago

I got the same problem: clearing the browser cache solved it

skndn60 commented 11 years ago

I have the same problem when deploying to Google App Engine. Works just fine on my local machine. From the source of the generated page I see the following entries for various JS libraries when running on GAE:

jquery-1.7.2.min.js from /static/grappelli jquery-ui-1.8.18.custom.min.js from /static/grappelli

grappelli.min.js from /static/grappelli

core.js from /static/admin RelatedObjectLookups.js from /static/admin jquery.js from /static/admin jquery.init.js from /static/admin actions.js from /static/admin

I've cleared the browser cache, ran collectstatic and have setup the static urls as per Google's docs. When I check these entries against a locally generated page, the JS entries match...

Unfortunately no solution yet. By the way, thanks for an awesome script...

ulmus commented 11 years ago

I had this issue, solved it by ensuring that the AppDirectoriesFinder is first among the STATICFILES_FINDERS, like this:

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    'django.contrib.staticfiles.finders.FileSystemFinder',
 )
sehmaschine commented 11 years ago

@ulmus that's a good point – we'll update the docs with that info.

idboehman commented 11 years ago

I had this issue today as well. I ensured that AppDirectoriesFinder was first in STATICFILES_FINDERS as well as making sure my STATIC_ROOT , STATICFILES_DIRS , and STATIC_URL were all set correctly.

The solution to my issue ended up being moving GRAPPELLI_INDEX_DASHBOARD from my local.py settings file and into my base.py settings file above all of the above declarations.

sehmaschine commented 11 years ago

@idboehman thanks for the hint, but I'm very certain that GRAPPELLI_INDEX_DASHBOARD is not related to the actions whatsoever. My guess is that this issue is caused by caching (could be browser–cache, could be old .pyc–files).

defrex commented 11 years ago

I've had this issue for a long time. The STATICFILES_FINDERS fix worked for me.

zzart commented 11 years ago

The way i did this was to create simlink to grappelli/static/admin (which has the js files in question) in my staticfiles folder. STATICFILES_FINDERS didn't help.

tufelkinder commented 11 years ago

This is what solved it for me as well, zzart.

Just guessing, but the issue appears to be that following the install instructions, django's built-in jquery library is loading after the grappelli jquery-1.7.2. Creating the link as you describe results in effectively loading the jquery library twice, but at least it's the same library.

ghost commented 11 years ago

having the same issue. Tried the GRAPPELLI_INDEX_DASHBOARD suggestion, clearing cache suggestion, the STATICFILES_FINDERS suggestion and made certain all of the paths for static files were to documentation standards. No luck. Perhaps I'll try the modification of the js suggestion but seems rather adhoc. oh well.

sehmaschine commented 11 years ago

@zzart if you need a symlink there´s something wrong with your staticfiles setup ... all staticfiles should be found automatically when doing collectstatic.

@tufelkinder djangos built–in jquery is overriden by grappelli (there is no content with jquery.min.js).

alberdonpi commented 11 years ago

In two months, I have had this issue 3 times, and every time I used a different way to solve it.

But I have found that if you follow the @ulmus comment about AppDirectoriesFinder, and inside your static folder, you replace your admin > js folder by your grapelli > static > admin > js folder, the problem is solved!

im-n1 commented 11 years ago

Hi guys, I was facing this issue and the core of this tricky issue is that jquery is there twice. U can see that when u look into html source in ur browser.

I didnt wanna use symlink, so I've added this to nginx site conf:

location = /static/admin/js/jquery.js {
    alias /dev/null;
}
sehmaschine commented 11 years ago

@grafa but the file /static/admin/js/jquery.js is empty, see https://github.com/sehmaschine/django-grappelli/blob/master/grappelli/static/admin/js/jquery.js

another idea – did you try running collectstatic with ignoring the original admin–files? python manage.py collectstatic --ignore django.contrib.admin

haganf commented 11 years ago

So I had this exact same problem... I took over a project that at some point was started pre 1.3 Django (currently 1.4). Turns out I had been using the old 'staticfiles' app and not 'django.contrib.staticfiles' and wasn't getting everything with collectstatic. After migrating over to django's static, collectstatic worked and no more admin issues!

im-n1 commented 11 years ago

@sehmaschine my solution wasn't 100%. I've started using collectstatic and it works now.

etratch commented 11 years ago

my problem was solved as follows::

STATICFILES_FINDERS = ( 'django.contrib.staticfiles.finders.AppDirectoriesFinder', 'django.contrib.staticfiles.finders.FileSystemFinder', )

sujeethmenon commented 11 years ago

Hi i having one issue .. I have created a js file for numeric key pad and wen i call from my application , Its not calling . i get error as "[ object object] has no method. Any help will be appreciated. Thanks in advance

restarian commented 10 years ago

Found it! Make sure to remove the old grappelli and admin files in your static root directory and then do a manage.py collectstatic again after this is changed.

STATICFILES_FINDERS = ( 'django.contrib.staticfiles.finders.AppDirectoriesFinder', 'django.contrib.staticfiles.finders.FileSystemFinder', } Now it stated to work without that error.

squarepegsys commented 10 years ago

I had the same problem with Filters using gunicorn and ngnix. I had AppDirectoriesFinder before FileSystemFinder in STATICFILES_FINDERS but it still didn't work. What did work is making sure that when the grappelli is using the admin/js/, that is is forcing it to use grappelli's admin javascripts, not the admin apps.

This is what my ngnix config looks like now:

   location /static/admin/js/ {
       root /usr/local/lib/python2.7/dist-packages/grappelli/;
 }
location /static/admin/media/ {
       root /usr/local/lib/python2.7/dist-packages/django/contrib/admin/static/admin/;
 }

 location /static/grappelli/ {
      root /usr/local/lib/python2.7/dist-packages/grappelli/;
    }

 location /static/ {
    # if asset versioning is used
    if ($query_string) {
        expires max;
      }
 }
brenouchoa commented 9 years ago

@squarepegsys thanks, your solution also solved my problem...

ecederstrand commented 9 years ago

With nginx, you should really just have one location /static/ pointing to your static project folder and then let ./manage.py collectstatic DTRT, respecting the collection order specified in settings.py. That way, your nginx and runserver environment will be much more comparable.

sdillinger commented 9 years ago

Same problem that's been reported for 2+ years. Tried all reasonable solutions. No luck.

sehmaschine commented 9 years ago

@sdillinger well, haven't been able to reproduce this for 2+ years. I'm pretty sure this is not related to grappelli but your server/django setup.

ajostergaard commented 8 years ago

It seems to me that the same symptom has multiple root causes depending on the environment.

In my case, 'runserver', the solution was to reverse STATICFILES_FINDERS as suggested above.

ajostergaard commented 8 years ago

ACTUALLY... In my case STATICFILES_FINDERS only partially solved the problem and, in fact, was a red herring.

What solved it for me was making sure grappelli loads before debug_toolbar:

INSTALLED_APPS = ( ... 'grappelli', 'debug_toolbar', ... )

myii commented 8 years ago

Have just encountered this problem for the second time so exerted some effort looking into it. The following discussion is based upon my setup but it wouldn't surprise me in the slightest if others are in exactly the same boat.

sehmaschine commented on 11 Aug @sdillinger well, haven't been able to reproduce this for 2+ years. I'm pretty sure this is not related to grappelli but your server/django setup.

@sehmaschine: I'm with you 100% -- in my case at least, it had nothing to do with Grappelli itself. As for reproducing (and fixing) the error -- perhaps I can help you with that...


TL;DR

A simple, working solution to this problem. First up, two important references:

http://django-grappelli.readthedocs.org/en/latest/quickstart.html#setup:

Open settings.py and add grappelli to your INSTALLED_APPS (before django.contrib.admin):

INSTALLED_APPS = (
    'grappelli',
    'django.contrib.admin',
)

https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#django-admin-option---clear:

--clear

Clear the existing files before trying to copy or link the original file.

A caveat:

Now the steps:

  1. Ensure you have 'grappelli' before 'django.contrib.admin' in INSTALLED_APPS, as shown in the reference above
  2. Run python manage.py collectstatic --noinput --clear
  3. Test from the browser, with full reload of the page with the filter button on it -- error should be resolved

Basic overview
Intro

With the steps shown below, I've been able to reproduce and fix the error 100% consistently, using the following setup:

  1. Django 1.8
  2. DEBUG = False
  3. Nginx + Gunicorn via. Unix socket

In any case, as long as the static files are being accessed at STATIC_ROOT, the following steps should work.

Reproducing the error

In order to reproduce the error, note that I am about to contradict the official instructions as shown above, because that is one of the ways that this problem could have occurred.

INSTALLED_APPS = (
    'django.contrib.admin',
    'grappelli',
)
$ python manage.py collectstatic --noinput
Copying '.../django/contrib/admin/static/admin/js/inlines.js'
Copying '.../django/contrib/admin/static/admin/js/collapse.js'
Copying '.../django/contrib/admin/static/admin/js/related-widget-wrapper.js'
Copying '.../django/contrib/admin/static/admin/js/calendar.js'
Copying '.../django/contrib/admin/static/admin/js/collapse.min.js'
Copying '.../django/contrib/admin/static/admin/js/urlify.js'
Copying '.../django/contrib/admin/static/admin/js/core.js'
Copying '.../django/contrib/admin/static/admin/js/jquery.js'
Copying '.../django/contrib/admin/static/admin/js/actions.min.js'
Copying '.../django/contrib/admin/static/admin/js/jquery.init.js'
Copying '.../django/contrib/admin/static/admin/js/inlines.min.js'
Copying '.../django/contrib/admin/static/admin/js/actions.js'
Copying '.../django/contrib/admin/static/admin/js/jquery.min.js'
Copying '.../django/contrib/admin/static/admin/js/timeparse.js'
Copying '.../django/contrib/admin/static/admin/js/SelectBox.js'
Copying '.../django/contrib/admin/static/admin/js/prepopulate.min.js'
Copying '.../django/contrib/admin/static/admin/js/SelectFilter2.js'
Copying '.../django/contrib/admin/static/admin/js/LICENSE-JQUERY.txt'
Copying '.../django/contrib/admin/static/admin/js/prepopulate.js'
Copying '.../django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js'
Copying '.../django/contrib/admin/static/admin/js/admin/DateTimeShortcuts.js'

21 static files copied to '.../static', 593 unmodified.

Fixing the error

The resolution steps are almost the same:

INSTALLED_APPS = (
    'grappelli',
    'django.contrib.admin',
)
$ python manage.py collectstatic --noinput
Copying '.../grappelli/static/admin/js/SelectFilter2.js'
Copying '.../grappelli/static/admin/js/collapse.min.js'
Copying '.../grappelli/static/admin/js/actions.min.js'
Copying '.../grappelli/static/admin/js/inlines.js'
Copying '.../grappelli/static/admin/js/urlify.js'
Copying '.../grappelli/static/admin/js/related-widget-wrapper.js'
Copying '.../grappelli/static/admin/js/collapse.js'
Copying '.../grappelli/static/admin/js/jquery.js'
Copying '.../grappelli/static/admin/js/jquery.min.js'
Copying '.../grappelli/static/admin/js/calendar.js'
Copying '.../grappelli/static/admin/js/prepopulate.js'
Copying '.../grappelli/static/admin/js/prepopulate.min.js'
Copying '.../grappelli/static/admin/js/actions.js'
Copying '.../grappelli/static/admin/js/core.js'
Copying '.../grappelli/static/admin/js/LICENSE-JQUERY.txt'
Copying '.../grappelli/static/admin/js/timeparse.js'
Copying '.../grappelli/static/admin/js/SelectBox.js'
Copying '.../grappelli/static/admin/js/inlines.min.js'
Copying '.../grappelli/static/admin/js/jquery.init.js'
Copying '.../grappelli/static/admin/js/admin/RelatedObjectLookups.js'
Copying '.../grappelli/static/admin/js/admin/DateTimeShortcuts.js'

21 static files copied to '.../static', 593 unmodified.
Why is the problem occurring?
How could this have happened?
  1. As in the steps shown above, could have the INSTALLED_APPS ordered wrongly
  2. Another cause could be that collectstatic was run for 'django.contrib.admin' before 'grappelli' was ever installed
  3. ...

Further details

The following points are from my basic investigations and not any meaningful experience. I'd be perfectly happy for a Django expert to come along and tell me I'm all wrong and there are better explanations and solutions. I just want to develop more robust, stable apps. Please take with a pinch of salt.

Everything hinges on how collectstatic works

https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#collectstatic:

On subsequent collectstatic runs (if STATIC_ROOT isn’t empty), files are copied only if they have a modified timestamp greater than the timestamp of the file in STATIC_ROOT. Therefore if you remove an application from INSTALLED_APPS, it’s a good idea to use the --clear option in order to remove stale static files.

  • Emphasis above is mine
  • Possible scenario:
  • Wrong static/admin/js in place
  • User has corrected ordering in INSTALLED_APPS
  • However, modification dates on system are unfavourable, i.e.:
  • grappelli/static/admin/js < static/admin/js
  • The result will be something like:
$ python manage.py collectstatic --noinput

0 static files copied to '.../static', 614 unmodified.
$ touch .../grappelli/static/admin/js/jquery.init.js 
$ python manage.py collectstatic --noinput
Copying '.../grappelli/static/admin/js/jquery.init.js'

1 static file copied to '.../static', 613 unmodified.
$ touch -d 2000-01-01 .../static/admin/js/jquery.init.js 
$ python manage.py collectstatic --noinput
Copying '.../grappelli/static/admin/js/jquery.init.js'

1 static file copied to '.../static', 613 unmodified.
$ find .../static/admin/js -type f -exec touch -d 2000-01-01 {} \;
$ python manage.py collectstatic --noinput
Copying '.../grappelli/static/admin/js/SelectFilter2.js'
Copying '.../grappelli/static/admin/js/collapse.min.js'
Copying '.../grappelli/static/admin/js/actions.min.js'
Copying '.../grappelli/static/admin/js/inlines.js'
Copying '.../grappelli/static/admin/js/urlify.js'
Copying '.../grappelli/static/admin/js/related-widget-wrapper.js'
Copying '.../grappelli/static/admin/js/collapse.js'
Copying '.../grappelli/static/admin/js/jquery.js'
Copying '.../grappelli/static/admin/js/jquery.min.js'
Copying '.../grappelli/static/admin/js/calendar.js'
Copying '.../grappelli/static/admin/js/prepopulate.js'
Copying '.../grappelli/static/admin/js/prepopulate.min.js'
Copying '.../grappelli/static/admin/js/actions.js'
Copying '.../grappelli/static/admin/js/core.js'
Copying '.../grappelli/static/admin/js/LICENSE-JQUERY.txt'
Copying '.../grappelli/static/admin/js/timeparse.js'
Copying '.../grappelli/static/admin/js/SelectBox.js'
Copying '.../grappelli/static/admin/js/inlines.min.js'
Copying '.../grappelli/static/admin/js/jquery.init.js'
Copying '.../grappelli/static/admin/js/admin/RelatedObjectLookups.js'
Copying '.../grappelli/static/admin/js/admin/DateTimeShortcuts.js'

21 static files copied to '.../static', 593 unmodified.
Repercussions

This issue remaining active for over 3 years is a testament to this collectstatic functionality. What makes it even more delicious is that the "bug" can resolve itself given the right conditions. An example:

In an ideal world:

Now if this ideal world already exists, please let me know. Perhaps even this issue could finally be closed!

"The File of Doom"

Finally, this whole discussion wouldn't be complete without identifying the offender, fingering the exact line of code that has caused so much pain!

I've already sneakily mentioned it above... and it is...:

If Grappelli wins the collectstatic battle, then you'll find it contains:

// dropped
// not used in grappelli
// kept this file to prevent 404

Yet if Django-Admin comes out trumps, you'll find:

/* Puts the included jQuery into our own namespace using noConflict and passing
 * it 'true'. This ensures that the included jQuery doesn't pollute the global
 * namespace (i.e. this preserves pre-existing values for both window.$ and
 * window.jQuery).
 */
var django = django || {};
django.jQuery = jQuery.noConflict(true);

NB: I am in no way advocating this method of getting the filter button working again -- just sharing this finding for the curious out there.

sehmaschine commented 8 years ago

@myii Thanks a lot for the research and the very detailed explanation. What you're saying makes sense indeed (still funny that I've never run across this issue with any projects we did).

Tatsh commented 8 years ago

@myii Thanks. I added the steps` to my deployment in Ansible like so, and then run collectstatic again (unfortunately):

- name: 'manage.py collectstatic'
  django_manage: app_path={{common_htdocs_dir}}/fos
                 command=collectstatic
                 settings=fos.settings
                 virtualenv={{common_htdocs_dir}}/fos-venv
  when: code.changed or code_deps.changed or settings.changed
  tags:
    - fos
    - collectstatic

# Next two steps, credits to @myii
# https://github.com/sehmaschine/django-grappelli/issues/214#issuecomment-158576652
- name: "Move Django's admin assets to avoid conflict with Grapelli's"
  command: mv {{common_htdocs_dir}}/fos/static/admin/js {{common_htdocs_dir}}/fos/static/admin/js-already-moved creates={{common_htdocs_dir}}/fos/static/admin/js-already-moved
  tags:
    - fos
    - collectstatic
    - grapelli

# Using command directly so ----no-post-process can be passed, for extra speed
- name: "Re-run collectstatic to replace admin assets with Grapelli's"
  command: '{{common_htdocs_dir}}/fos-venv/bin/python ./manage.py collectstatic --no-color --noinput --no-post-process chdir={{common_htdocs_dir}}/fos'
  tags:
    - fos
    - collectstatic

Luckily Grapelli does not need post-processing, and only JS is affected.

fchevitarese commented 8 years ago

I got the same error, added this and it worked STATICFILES_FINDERS = ( 'django.contrib.staticfiles.finders.AppDirectoriesFinder', 'django.contrib.staticfiles.finders.FileSystemFinder', }

;)

marcoooo commented 8 years ago

Hi all, Django 1.9.8 / Grappelli 2.8., this problem still occurs, even in production with static files setup.

Is there any 'simple' solution for this ? Noting that in my project, admin js is never loaded any time.