Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working #2

Closed
mpena2099 opened this issue Nov 25, 2014 · 10 comments
Closed

Not working #2

mpena2099 opened this issue Nov 25, 2014 · 10 comments

Comments

@mpena2099
Copy link

Hi!

My code is not working:

from django.contrib import admin
from models import Curriculo
from advanced_filters.admin import AdminAdvancedFiltersMixin

class CurriculoAdmin(admin.ModelAdmin, AdminAdvancedFiltersMixin):
  list_filter = ('nome', 'cargo_pretendido1',)

  # select from these fields in the advanced filter creation form
  advanced_filter_fields = (
    'nome', 'cargo_pretendido1'
  )  

admin.site.register(Curriculo, CurriculoAdmin)

Error message: "Cannot create a consistent method resolution order (MRO) for bases AdminAdvancedFiltersMixin, ModelAdmin"

Any ideia?

Thanks!

@asfaltboy
Copy link
Member

I believe our mixin, being a partial/mixin (or sub-class) implementation of a ModelAdmin, should be placed before the admin.ModelAdmin in the class declaration. This SO answer explains it nicely. Try using this line and tell me how it goes:

class CurriculoAdmin(AdminAdvancedFiltersMixin, admin.ModelAdmin):
...

EDIT: In fact, taking a look at the code, this whole situation can be avoided by simply having our mixin inheriting from object instead of ModelAdmin over at admin.py module.

@mpena2099
Copy link
Author

New error:

TypeError at /admin/curriculos/curriculo/
init() takes at least 2 arguments (1 given)

in /(...)/advanced_filters/admin.py in changelist_view
81. response = self.adv_filters_handle(request, kwargs)

:-/

@asfaltboy
Copy link
Member

First of all, thanks for checking @mpena2099! It's rare to see visitors around here :)
As you must have noticed, the code hadn't been touched for quite a while.

But it's not to say the package wasn't being used. On the contrary, the application has evolved quite a bit from the initial state it was in when I initially published it to github (while still using the same core functionality).

In fact, the interest you've shown has motivated me to merge the changes from our branch into github as well as add some documentation, to the best of my ability.

I suggest you follow this thread as I will reference it when I finally push the update, hopefully that won't be too long from now.

asfaltboy added a commit that referenced this issue Nov 26, 2014
see CHANGELOG/README for details

closes issue #2
@mpena2099
Copy link
Author

Thanks @asfaltboy! :D

@mpena2099
Copy link
Author

Advanced Filter button created but... don't do nothing.

First of all, it is necessary to add 'easy_select2' to INSTALLED_APPS. Now I see the errors below on error console from Safari:

[Warning] Invalid CSS property declaration at: * (select2.min.css, line 1)
[Error] TypeError: 'undefined' is not a function (evaluating 'e(window)')
    (função anônima) (jquery.magnific-popup.js, line 4)
[Error] ReferenceError: Can't find variable: grp
    global code (advanced-filters.js, line 154)
[Error] TypeError: 'undefined' is not an object (evaluating '$.magnificPopup.instance')
    (função anônima) (curriculo, line 327)
[Error] Failed to load resource: the server responded with a status of 404 (Not Found) (http://127.0.0.1:8000/static/easy_select2/vendor/jquery/jquery.js, line 0)

@marklr
Copy link
Collaborator

marklr commented Nov 26, 2014

Is your STATIC_ROOT configured properly?

@mpena2099
Copy link
Author

Yes @marklr, and I ran the command "collectstatic"...

@asfaltboy
Copy link
Member

Hi @mpena2099, first of all you are right, easy_selecty2 should be added to support easy_select2 field usage. Will have to add this to the docs.

Second, our use case platform uses django-grappelli, hence the templates provided occasionally reference grp elements, as explained in the readme.

This might need some clarification in the docs, but basically anything (templates and static js/css files) can be overridden for different styling and front-end functionality, if desired. Take a peek in the js/html files, and let me know if you still have trouble implementing your own (non grappelli) template/frontend.

I believe our current frontend implementation requires jquery, and easy_select2 providе their own (in their "static/vendor" directory, as explained here.

If you are debugging locally there is no need to run collectstatic, rather make sure you have DEBUG turned on and the staticfiles app is enabled.

@asfaltboy
Copy link
Member

@mpena2099; I decided that we might as well use the jQuery bundled with easy_select2 if we're gonna require them.

So this commit should now fix the issues you had when using the changelist on a non-grappelli.

Please note that the change form (for editing existing filters), still overrides grappelli's template, and will require another commit to fix. I've listed this in the short TODO list in the readme. So anyone can feel free to chime in and submit pull request on these things whenever they have some time.

@mpena2099
Copy link
Author

Hi!

OK, now it works... with Grappelli! (I was already thinking of using it in my project)

But... without Grappelli still some errors (ALL, I think, related to Grappelli):

[Error] ReferenceError: Can't find variable: grp
    global code (actions.js, line 136)
[Error] TypeError: 'undefined' is not a function (evaluating '$(document)')
    (função anônima) (curriculo, line 29)
[Error] TypeError: 'undefined' is not an object (evaluating '$.fn')
    (função anônima) (orig_inlines.js, line 18)
[Error] TypeError: 'undefined' is not a function (evaluating '$("#form-group > tbody > tr")')
    (função anônima) (curriculo, line 865)
[Log] selected operator: iexact (advanced-filters.js, line 58)
[Error] Failed to load resource: the server responded with a status of 404 (Not Found) (http://127.0.0.1:8000/static/easy_select2/vendor/jquery/jquery.js, line 0)

Without Grappelli:
adv1

With Grappelli:
adv2

Good enough to me! Now... I'm late to make other changes in my system but I'll be back soon to try to help in developing the project.

Thanks! :D

nkonin pushed a commit to nkonin/django-advanced-filters that referenced this issue Apr 7, 2017
Readable Advanced Filters in forms and admin
zeevt pushed a commit to zeevt/django-advanced-filters that referenced this issue Jul 11, 2021
* filter without creating new object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants