modlinltd / django-advanced-filters Goto Github PK
View Code? Open in Web Editor NEWAdd advanced filtering abilities to Django admin
Home Page: https://pypi.org/project/django-advanced-filters/
License: MIT License
Add advanced filtering abilities to Django admin
Home Page: https://pypi.org/project/django-advanced-filters/
License: MIT License
Just tried this out with a Django 2.X project and immediately hit this error during initial migration:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 347, in execute
django.setup()
File "/usr/local/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python3.6/site-packages/django/apps/registry.py", line 112, in populate
app_config.import_models()
File "/usr/local/lib/python3.6/site-packages/django/apps/config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
File "/usr/local/lib/python3.6/site-packages/advanced_filters/models.py", line 16, in <module>
class AdvancedFilter(models.Model):
File "/usr/local/lib/python3.6/site-packages/advanced_filters/models.py", line 23, in AdvancedFilter
related_name='created_advanced_filters', verbose_name=_('Created by'))
TypeError: __init__() missing 1 required positional argument: 'on_delete'
As we all know, this was a breaking change introduced by django 2.X. I would be happy to create a PR for this, but I assume there could be other issues regarding django 2.X compatibility. I was wondering if there is a current effort ongoing already for 2.X compatibility or if I should just start by submitting a PR for this particular issue.
With pip3 and without locales set I get the following errors:
Collecting django-advanced-filters==1.1.0 (from -r deploy/docker-base/requirements.txt (line 1))
Downloading https://files.pythonhosted.org/packages/45/68/98aed982c7a56eb47dfed7cf47703c533b7bdc4ea65f85bae7fbf98c48eb/django-advanced-filters-1.1.0.tar.gz (72kB)
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-o9zraagc/django-advanced-filters/setup.py", line 62, in <module>
long_description=get_full_description(),
File "/tmp/pip-build-o9zraagc/django-advanced-filters/setup.py", line 40, in get_full_description
CHANGELOG = changelog.read()
File "/usr/lib/python3.6/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1016: ordinal not in range(128)
I need to do the following to fix it:
locale-gen en_US.UTF-8
export LANG=en_US.UTF-8 LANGUAGE=en_US.en LC_ALL=en_US.UTF-8
Can't we do something to avoid it ? It seems to be only because of the CHANGELOG.
When running collect static with a specialized staticfiles_storage, collect static will break.
This is the same issue as makinacorpus/django-leaflet#149
Utilize selenium in tests, perhaps with pytest-selenium, here's an introduction blog.
Hello!
I have custom User model, which inherits AbstractBaseUser and doesn't have Group relation. So when i use filter mixin, i get this exception:
Traceback (most recent call last):
File "python2.7/site-packages/advanced_filters/admin.py", line 34, in lookups
return AdvancedFilter.objects.filter_by_user(request.user).filter(
File "python2.7/site-packages/advanced_filters/models.py", line 13, in filter_by_user
return self.filter(Q(users=user) | Q(groups__in=user.groups.all()))
File "python2.7/site-packages/django/utils/functional.py", line 235, in inner
return func(self._wrapped, *args)
AttributeError: 'User' object has no attribute 'groups'
Can you add a attribute checking in UserLookupManager.filter_by_user or something?
using latest stable django (1.8.7) and python 3.5 - not compatible at this moment? when applying any filter it returns this error:
name 'basestring' is not defined
exception location: env/lib/python3.5/site-packages/advanced_filters/form_helpers.py in clean, line 29
a fix could by as mentioned here http://www.rfk.id.au/blog/entry/preparing-pyenchant-for-python-3/
"These are both errors in Python 3 since there's no such thing as 'unicode' or 'basestring'. But it's pretty simple to normalise the vocabulary between the two versions:
try:
unicode = unicode
except NameError:
str = str
unicode = str
bytes = bytes
basestring = (str,bytes)
else:
str = str
unicode = unicode
bytes = str
basestring = basestring "
Not sure how to implement this (rookie python level). Someone got an idea?
I encountered a decode error.
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa1 in position 4: invalid start byte
`base string:
handet to lib/python3.6/site-packages/simplejson/decoder.py
b'eyJjaGlsZHJlbiI6IFtbInBvcnRhbF9faWV4YWN0IiwgIkZsdWVnZV9kZSJdXSwgImNvbm5lY3RvciI6ICJBTkQiLCAibmVnYXRlZCI6IGZhbHNlfQ=='
string decoded
b'm\xec\x89\x8d\xa1\xa5\xb1\x91\xc9\x95\xb8\x88\xe8\x81ml\x89\xc1\xbd\xc9\xd1\x85\xb1}}\xa5\x95\xe1\x85\x8d\xd0\x88\xb0\x80\x89\x19\xb1\xd5\x95\x9d\x95}\x91\x94\x89ut\xb0\x80\x89\x8d\xbd\xb9\xb9\x95\x8d\xd1\xbd\xc8\x88\xe8\x80\x89\x059\x10\x88\xb0\x80\x89\xb9\x95\x9d\x85\xd1\x95\x90\x88\xe8\x81\x99\x85\xb1\xcd\x95\xf4'
encode again
b'beyJjaGlsZHJlbiI6IFtbInBvcnRhbF9faWV4YWN0IiwgIkZsdWVnZV9kZSJdXSwgImNvbm5lY3RvciI6ICJBTkQiLCAibmVnYXRlZCI6IGZhbHNlfQ='
b'm\xec\x89\x8d\xa1\xa5\xb1\x91\xc9\x95\xb8\x88\xe8\x81ml\x89\xc1\xbd\xc9\xd1\x85\xb1}}\xa5\x95\xe1\x85\x8d\xd0\x88\xb0\x80\x89\x19\xb1\xd5\x95\x9d\x95}\x91\x94\x89ut\xb0\x80\x89\x8d\xbd\xb9\xb9\x95\x8d\xd1\xbd\xc8\x88\xe8\x80\x89\x059\x10\x88\xb0\x80\x89\xb9\x95\x9d\x85\xd1\x95\x90\x88\xe8\x81\x99\x85\xb1\xcd\x95\xf4'
`
there is an b and a ' at the start of the submited string.
i hotfixed this by
/lib/python3.6/site-packages/advanced_filters/q_serializer.py
def loads(self, string, raw=False):
string = string.replace('b'','')
string = string.replace(''', '')
if self.b64_enabled:
d = json.loads(base64.b64decode(string))
else:
d = json.loads(string)
if raw:
return d
return self.deserialize(d)
Hi, great proyect, It's possible get working with rest querys instead of models aproach?
I'm trying to integrate advanced_filters into a project that already uses django_select2
and has SELECT2_CSS
and SELECT2_JS
settings set, but there are JS console errors that select2 is not a function
.
The only difference I can see is that my select2 major version is 4.x.x while you expect 3.x.x.
Any thoughts?
When I attempt to install from PyPi I receive the following. I have verified on two separate systems and do not believe it to be something on my end. Should there be something after "versions:" on the third line below? Thanks.
$ pip install django-advanced-filters
Collecting django-advanced-filters
Could not find a version that satisfies the requirement django-advanced-filters (from versions: )
No matching distribution found for django-advanced-filters
It looks like the "one of" operator maps to "iregex" under the hood. Does this mean that the value should be a regular expression? The confusion hit for me when I went to input the value, and it provided an autocomplete field which I was only allowed to select one of (I expected to see an interface that would allow me to choose multiple values). So, should the value of this operator type be a regex?
As of right now, all operators are available regardless of the field type. For instance, the admin section would allow you to choose the "Equals" or "Greater Than" operators for a boolean field. It would be great if the UI would only present appropriate operators based on the field type. I am not certain as to whether this is something I could already implement in my admin class, or if this should be a feature request, in which case I am happy to look into whipping up a PR. Thanks!
Hi,
Here's the error I get when trying to click on one of the created advanced filters in the admin.
Reverse for 'advanced_filters_advancedfilter_change' not found. 'advanced_filters_advancedfilter_change' is not a valid view function or pattern name.
django version: 1.11.3
python version: 3.4.5
django-advanced-filters==1.0.7.1
In advanced_filters/templates/admin/advanced_filters.html
there's a reverse url lookup for admin:advanced_filters_advancedfilter_change
, but django can't seem to find that url name.
The url name doesn't seem to be defined anywhere in the project. E.g., grep -r advanced_filters_advancedfilter_change *
only occurs in `advanced_filters/templates/admin/advanced_filters.html. Nowhere else. Where is that url name set? I'm really confused and I feel like I'm missing something really simple.
Thanks
Thank you for your efforts on this feature!
I see the filter form, but it says the following in the field dropdown.
"Or (mark an or between blocks)"
Screen shot attached.
Can someone help me understand what I am doing wrong?
thanks,
I installed django edge.
Then installed modlinltd/django-advanced-filters
Django 1.8.11
Windows.
from advanced_filters.admin import AdvancedFilterAdmin, AdminAdvancedFiltersMixin
class Cilisting1Admin( AdminAdvancedFiltersMixin, admin.ModelAdmin ):
..... some other stuff ....
list_filter = (
'wc_idea_date',
'actual_implementation_date',
)advanced_filter_fields = (
'owner', 'originator', 'project_number',
)
http://django-edge.readthedocs.org/en/latest/#quick-start
django-admin.py startproject --template=
https://github.com/arocks/edge/archive/master.zip -extension=py,md,html,env my_proj
cd my_proj
pip install -r requirements.txt
cd src
cp my_proj/settings/local.sample.env my_proj/settings/local.env
python manage.py migrate
python manage.py createsuperuser
python manage.py runserver 0.0.0.0:8000
python manage.py startapp cilist1
edit cilist1 models.py
edit base.py - add clist1 app
python manage.py makemigrations cilist1
python manage.py sqlmigrate cilist1 0001
python manage.py makemigrations
python manage.py migrate
edit cilist1 admin.py
python manage.py runserver 0.0.0.0:8000
An aside... I moved to Windows...
set wpip=c:\p2\Python27\Scripts\pip
%wpip% install -r requirements.txt
cd src
python manage.py runserver 0.0.0.0:8000
%wpip% install django-advanced-filters
Install from pypi: pip install django-advanced-filters
Add both 'advanced_filters' and 'easy_select2' to INSTALLED_APPS.
Add url(r'^advanced_filters/', include('advanced_filters.urls')) to your project's urlconf.
Run python manage.py syncdb
%wpip% install django-grappelli
added grapelli to installed apps.
Are there any best practices around how to further limit the results of the GetFieldName
view? In my particular use case, all of the objects in my system belong to an "account" via foreign key, and I would like to limit the choices to include only those with the same "account" as the filterset being created. For reference, I am looking to implement something similar to the "forwarding" feature of Django Autocomplete Light.
https://django-autocomplete-light.readthedocs.io/en/master/tutorial.html?highlight=forwarded
The idea being that once the "account" is selected in the filterset, it would be forwarded to the GetFieldChoices
view, and then used to further limit the choices returned.
I am messing around with trying to implement this myself, but just wanted to see if anybody could offer some guidance or best practices.
Without migrations syncdb
(or migrate --run-syncdb
) command must be used.
Hi, I have installed django-grappelli followed by django-advanced-filters. Although I see the "Advanced Filters" button, it does not open a popup on clicking it. would be of great help if someone can help me with this.
Thanks
Would it be possible to make filters without saving them, a little like a search bar ? Instead of having only Save
and Filter and save
, having button Filter
?
We ought to support the official latest release; while not breaking previous compatibility if possible.
Currently, at least 1 error is raised:
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\Dank\Anaconda3\lib\site-packages\django\core\management\__init__.py", line 353, in execute_from_command_line
utility.execute()
File "C:\Users\Dank\Anaconda3\lib\site-packages\django\core\management\__init__.py", line 327, in execute
django.setup()
File "C:\Users\Dank\Anaconda3\lib\site-packages\django\__init__.py", line 18, in setup
apps.populate(setting.INSTALLED_APPS)
File "C:\Users\Dank\Anaconda3\lib\site-packages\django\apps\registry.py", line 115, in populate
app_config.ready()
File "C:\Users\Dank\Anaconda3\lib\site-packages\django\contrib\admin\apps.py", line 22, in ready
self.module.autodiscover()
File "C:\Users\Dank\Anaconda3\lib\site-packages\django\contrib\admin\__init__.py", line 26, in autodiscover
autodiscover_modules('admin', register_to=site)
File "C:\Users\Dank\Anaconda3\lib\site-packages\django\utils\module_loading.py", line 50, in autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
File "C:\Users\Dank\Anaconda3\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 622, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "C:\Users\Dank\Anaconda3\lib\site-packages\advanced_filters\admin.py", line 6, in <module>
from django.contrib.admin.util import unquote
ImportError: No module named 'django.contrib.admin.util'
(originally reported by Kato, Daniel D)
Hello! I'm using this module with django 1.11.
It works fine but
This means that to use advanced-filters in Django 1.5 admin, you'd have to probably include your own jQuery (1.9 or later) and add it to global namespace prior to other scripts in AdvancedFilterForm.Meta.
Can you please specify how should i do it?
From the console:
TypeError: $(...).datepicker is not a function
Hey bro
how can I use this cool module in my user side ?
Howdy,
How would I go about having a custom filter in the advanced_filter_fields list?
I have a scenario where I have a Person model with gender defined as a boolean field, but I'd like to give admin users the option to filter by "Male"/"Female" instead of by True/False.
I can use something like the GenderListFilter below in the admin page, but how do I go about doing something similar with advanced filters?
Thanks.
class Person(models.Model):
is_male = models.BooleanField(verbose_name='Is Male', blank=False, null=False, default=False)
class GenderListFilter(admin.SimpleListFilter):
title = 'Gender'
parameter_name = 'gender'
def lookups(self, request, model_admin):
return (
('M', 'Male'),
('F', 'Female')
)
def queryset(self, request, queryset):
if not self.value():
return queryset
if self.value().lower() == 'm':
return queryset.filter(is_male=True)
else:
return queryset.filter(is_male=False)
Hello there, I've installed latest django-advanced-filters using following command:
pip install -e "git://github.com/modlinltd/django-advanced-filters.git@develop#egg=django-advanced-filters"
but still i face following error:
from django.core.urlresolvers import reverse
ModuleNotFoundError: No module named 'django.core.urlresolvers'
any idea what could be the problem?
What is the reason to use these requirements?
install_requires=[
'django-braces==1.4.0',
'simplejson==3.6.5',
],
These versions are very outdated.
Why not to use for example django-braces>=1.4.0
or simplejson>=3.6.5,<4.0.0
File "/Users/cloud/src/django/cyq/env/lib/python2.7/site-packages/django/contrib/admin/decorators.py", line 28, in _model_admin_wrapper
admin_site.register(models, admin_class=admin_class)
File "/Users/cloud/src/django/cyq/env/lib/python2.7/site-packages/django/contrib/admin/sites.py", line 104, in register
if model._meta.abstract:
AttributeError: type object 'AdminAdvancedFiltersMixin' has no attribute '_meta'
Looks like if I added the mixin to the model before do migration, it errors.
But if I just migrate first and add the mixin later, it works. Nonetheless, it is a problem.
We currently engage the prepopulated easy-select2 allowing only a single choice.
When advanced filters is enabled for mymodel
and mymodel
contains a charfield that can be null (and have a null entry in the database), this raise the following exception since the new version:
Traceback:
File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/exception.py" in inner
34. response = get_response(request)
File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/base.py" in _get_response
126. response = self.process_exception_by_middleware(e, request)
File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/base.py" in _get_response
124. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python3.6/dist-packages/django/views/generic/base.py" in view
68. return self.dispatch(request, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/django/utils/decorators.py" in _wrapper
45. return bound_method(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/django/views/decorators/csrf.py" in wrapped_view
54. return view_func(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/braces/views/_forms.py" in dispatch
24. return super(CsrfExemptMixin, self).dispatch(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/braces/views/_access.py" in dispatch
407. request, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/django/views/generic/base.py" in dispatch
88. return handler(request, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/advanced_filters/views.py" in get
75. choices, key=itemgetter(0))]
Exception Type: TypeError at /admin/advanced_filters/field_choices/api.mymodel/description
Exception Value: '<' not supported between instances of 'NoneType' and 'str'
If I create an admin model :
class MyModelAdmin(AdminAdvancedFiltersMixin, admin.ModelAdmin):
advanced_filter_fields = ['related_obj'] # related_obj is a foreign key
And try to create a custom filter with related_obj
+ EQUALS
+ 1
I get the following traceback when executing the filter:
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
149. response = self.process_exception_by_middleware(e, request)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
147. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/options.py" in wrapper
541. return self.admin_site.admin_view(view)(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in _wrapped_view
149. response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/views/decorators/cache.py" in _wrapped_view_func
57. response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/sites.py" in inner
244. return view(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/advanced_filters/admin.py" in changelist_view
113. ).changelist_view(request, extra_context=extra_context)
File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in _wrapper
67. return bound_func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in _wrapped_view
149. response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in bound_func
63. return func.__get__(self, type(self))(*args2, **kwargs2)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/options.py" in changelist_view
1470. self.list_max_show_all, self.list_editable, self)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/views/main.py" in __init__
78. self.queryset = self.get_queryset(request)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/views/main.py" in get_queryset
326. new_qs = filter_spec.queryset(request, qs)
File "/usr/local/lib/python2.7/dist-packages/advanced_filters/admin.py" in queryset
53. return queryset.filter(query).distinct()
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in filter
790. return self._filter_or_exclude(False, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in _filter_or_exclude
808. clone.query.add_q(Q(*args, **kwargs))
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/query.py" in add_q
1243. clause, _ = self._add_q(q_object, self.used_aliases)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/query.py" in _add_q
1263. current_negated, allow_joins, split_subq)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/query.py" in _add_q
1269. allow_joins=allow_joins, split_subq=split_subq,
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/query.py" in build_filter
1194. lookup_class = field.get_lookup(lookups[0])
File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/related.py" in get_lookup
693. raise TypeError('Related Field got invalid lookup: %s' % lookup_name)
Exception Type: TypeError at /admin/api/mymodel/
Exception Value: Related Field got invalid lookup: iexact
Am I doing something wrong ?
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!
Howdy,
What would you think of having an option to share a filter with other users/groups? I'm running into a use case where users are creating the same filters over and over again, and even tho I could extract those common filters and bake them into my application, I think a more flexible approach would be to allow users to mark a filter as "shared" or "public.
Thoughts?
I'm using django-advanced-filters with django 1.8 on python2.7 django-advanced-filters==1.0.1 django-braces==1.4.0 django-easy-select2==1.2.5.
It works fine, but when I try to modify a filter, it fails.
Full bug details are at:
http://stackoverflow.com/questions/36098971/django-advanced-filters-grp-tags-is-not-a-valid-tag-library
I even tried making the advanced_filter_fields simpler but it still fails to modify it.
I really hope you can fix this or provide a workaround.
thanks
I've just upgraded an old django project from 1.3 -> 1.8 and am trying to add django-advanced-features to replace an old custom filtering application.
I've installed django_advanced_filters 1.0.5, and django_easy_select2 1.2.5. I've followed the installation guide and successfully added the AdminAdvancedFiltersMixin
to one of my models. I can see the admin templates are loading correctly but I seem to be getting JS errors related to select2.
E.g. on http://localhost:8080/admin/advanced_filters/advancedfilter/2/
I see:
Uncaught TypeError: Cannot read property 'fn' of undefined
at select2.min.js:21
at select2.min.js:21
And on my model changelist page (http://localhost:8080/admin/mymodel/
):
select2.min.js:21 Uncaught TypeError: Cannot read property 'fn' of undefined
at select2.min.js:21
at select2.min.js:21
advanced-filters.js:140 Uncaught TypeError: $(...).select2 is not a function
at HTMLInputElement.<anonymous> (advanced-filters.js:140)
at Function.each (jquery.min.js:2)
at m.fn.init.each (jquery.min.js:2)
at OperatorHandlers.self.destroy (advanced-filters.js:139)
at HTMLDocument.<anonymous> (advanced-filters.js:150)
at j (jquery.min.js:2)
at Object.fireWith [as resolveWith] (jquery.min.js:2)
at Function.ready (jquery.min.js:2)
at HTMLDocument.J (jquery.min.js:2)
This looks to me like some kind of jquery load order issue, and I'm aware django does some funny things with various versions, but I'm a bit stuck on how to debug. Can anyone point me in the right direction? I did wonder if it's due to the several difference versions of jquery loading and re-initialising $
, but I believe django does some clever stuff to namespace the versions. In case it's helpful here are the .js
files loading on my model changelist page:
jsi18n/ 200 script (index) 2.7 KB 246 ms
core.js 200 script (index) 7.8 KB 89 ms
jquery.js 200 script (index) 278 KB 126 ms
jquery.init.js 200 script (index) 557 B 88 ms
RelatedObjectLookups.js 200 script (index) 4.8 KB 113 ms
actions.js 200 script (index) 5.0 KB 118 ms
urlify.js 200 script (index) 6.3 KB 116 ms
prepopulate.js 200 script (index) 1.6 KB 115 ms
select2.min.js 200 script (index) 59.0 KB 12 ms
jquery.min.js 200 script (index) 93.9 KB 14 ms
orig_inlines.js 200 script (index) 11.3 KB 14 ms
jquery.magnific-popup.js 200 script (index) 20.7 KB 20 ms
advanced-filters.js 200 script (index) 5.0 KB 22 ms
jquery_pre.js 200 script (index) 298 B 7 ms
jquery.min.js 200 script (index) 29.5 KB 44 ms
jquery_post.js 200 script (index) 313 B 10 ms
toolbar.js 200 script (index) 12.4 KB 8 ms
toolbar.sql.js 200 script (index) 584 B 10 ms
toolbar.template.js 200 script (index) 589 B 11 ms
we are using latest django-easy-select2 and simplejson for our project requirement. but when we are try to install django-advanced-filters this will start to auto download old versions of Requirements. I think you should use latest version of all Requirements.
We are using this command to install (for ref.)
pip install django-advanced-filters
Great lib!
I'm running Django 1.10 with Python3.5.
From my admin interface, I'm able to see the ADVANCED FILTER button. I can click it and it opens the interface, where I can enter a title, select fields etc. However, I cannot SAVE / SAVE & FILTER NOW! or "Add another Field". The only link that works is Cancel...
I've added 'easy_select2' to my installed_apps (something which isn't mentioned on this GitHub page, but is on the pypi page.
Javascript crash on https://github.com/modlinltd/django-advanced-filters/blob/master/advanced_filters/static/advanced-filters/advanced-filters.js#L140
removing this line fix the issue as query-value is not a select form and select2 seems to work only on select form.
I have no idea if it's intended
Hi, thank you for building django-advanced-filters
. Trying to set up as described in README. After running migrate, getting this error:
root@758956a011f8:/usr/src/myapp# python manage.py migrate
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.5/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.5/site-packages/django/core/management/__init__.py", line 341, in execute
django.setup()
File "/usr/local/lib/python3.5/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python3.5/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/usr/local/lib/python3.5/site-packages/django/apps/config.py", line 90, in create
module = import_module(entry)
File "/usr/local/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 665, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "/usr/local/lib/python3.5/site-packages/easy_select2/__init__.py", line 7, in <module>
from easy_select2.utils import (
File "/usr/local/lib/python3.5/site-packages/easy_select2/utils.py", line 6, in <module>
from easy_select2.widgets import Select2Mixin, Select2, Select2Multiple
File "/usr/local/lib/python3.5/site-packages/easy_select2/widgets.py", line 16, in <module>
static('easy_select2/js/easy_select2.js'),
File "/usr/local/lib/python3.5/site-packages/django/templatetags/static.py", line 163, in static
return StaticNode.handle_simple(path)
File "/usr/local/lib/python3.5/site-packages/django/templatetags/static.py", line 112, in handle_simple
if apps.is_installed('django.contrib.staticfiles'):
File "/usr/local/lib/python3.5/site-packages/django/apps/registry.py", line 225, in is_installed
self.check_apps_ready()
File "/usr/local/lib/python3.5/site-packages/django/apps/registry.py", line 124, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
Is Django 1.10+ supported?
FYI,
root@758956a011f8:/usr/src/myapp# django-admin --version
1.10.2
root@758956a011f8:/usr/src/myapp# python --version
Python 3.5.2```
Thank you.
Howdy,
I'm facing an issue where the "advanced filter" button doesn't show up in the admin page (Django 1.9) if I have another mixin loaded first.
The mixin being loaded first is from django-import-export: https://github.com/django-import-export/django-import-export/blob/master/import_export/admin.py#L401
eg.
class WhateverAdmin(ImportExportMixin, AdminAdvancedFiltersMixin, admin.ModelAdmin):
pass
Anyone ever experienced that?
Thanks.
Hi.
After upgrading to Django 2.1 and changing to the advance_filters development branch I got the following error.
...
File "/usr/local/lib/python3.6/site-packages/advanced_filters/forms.py", line 236, in forms
forms.append(self.empty_form) # add initial empty form
File "/usr/local/lib/python3.6/site-packages/advanced_filters/forms.py", line 218, in empty_form
empty_permitted=True,
File "/usr/local/lib/python3.6/site-packages/advanced_filters/forms.py", line 193, in init
super(AdvancedFilterQueryForm, self).init(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/forms/forms.py", line 104, in init
'The empty_permitted and use_required_attribute arguments may '
ValueError: The empty_permitted and use_required_attribute arguments may not both be True.
...
After debugging I found out that in the empty_form method inside advanced_filters/forms.py in the form constructor is probably missing the the use_required_attribute=False parameter.
After I added it, the advance_filters restarted to work.
This issue happens because in the django BaseForm init the use_required_attribute argument is set to true by default.
Could somebody add use_required_attribute=False to the form constructor in the empty_form method?
Thanks
Would it be possible to implement this package such that an advanced filter could be executed without the need to title or save it? The screenshot indicates saving is mandatory - if it were optional, the ability to run ad-hoc filters and save only after reviewing results would be preferable...
is it particularly hard to implement those?
For example, a boolean field can be only true/false (yes/no) displayed by a radio button widget, a choice field with e.g 2-5 choices can be "one of" displayed by a multi-select checkbox widget.
For examples, see Django's ticket system:
Django uses trac's "custom" query feature:
Which use a different UI for and/or selection, and also allow grouping by a field, (which can be it's own feature by the way):
It looks like one migrations is missing :
Migrations for 'advanced_filters':
0003_auto_20180430_1634.py:
- Alter field created_at on advancedfilter
- Alter field created_by on advancedfilter
- Alter field groups on advancedfilter
- Alter field title on advancedfilter
- Alter field url on advancedfilter
- Alter field users on advancedfilter
I can make a PR but I would need a new release on pypi ? Could someone do it ?
version: 1.0.7.1
Thank you,
I get this exception migrating with oracle backend (Django==1.11.13 cx-Oracle==6.3.1)
Applying advanced_filters.0001_initial...Traceback (most recent call last):
File "/home/urb/.ia/lib/python3.4/site-packages/django/db/backends/utils.py", line 62, in execute
return self.cursor.execute(sql)
File "/home/urb/.ia/lib/python3.4/site-packages/django/db/backends/oracle/base.py", line 497, in execute
return self.cursor.execute(query, self._param_generator(params))
cx_Oracle.DatabaseError: ORA-00910: specified length too long for its datatype
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 22, in
execute_from_command_line(sys.argv)
File "/home/urb/.ia/lib/python3.4/site-packages/django/core/management/init.py", line 364, in execute_from_command_line
utility.execute()
File "/home/urb/.ia/lib/python3.4/site-packages/django/core/management/init.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/urb/.ia/lib/python3.4/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/urb/.ia/lib/python3.4/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/home/urb/.ia/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 204, in handle
fake_initial=fake_initial,
File "/home/urb/.ia/lib/python3.4/site-packages/django/db/migrations/executor.py", line 115, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "/home/urb/.ia/lib/python3.4/site-packages/django/db/migrations/executor.py", line 145, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "/home/urb/.ia/lib/python3.4/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "/home/urb/.ia/lib/python3.4/site-packages/django/db/migrations/migration.py", line 129, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/home/urb/.ia/lib/python3.4/site-packages/django/db/migrations/operations/models.py", line 97, in database_forwards
schema_editor.create_model(model)
File "/home/urb/.ia/lib/python3.4/site-packages/django/db/backends/base/schema.py", line 319, in create_model
self.execute(sql, params or None)
File "/home/urb/.ia/lib/python3.4/site-packages/django/db/backends/base/schema.py", line 136, in execute
cursor.execute(sql, params)
File "/home/urb/.ia/lib/python3.4/site-packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/home/urb/.ia/lib/python3.4/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/home/urb/.ia/lib/python3.4/site-packages/django/db/utils.py", line 94, in exit
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/urb/.ia/lib/python3.4/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/home/urb/.ia/lib/python3.4/site-packages/django/db/backends/utils.py", line 62, in execute
return self.cursor.execute(sql)
File "/home/urb/.ia/lib/python3.4/site-packages/django/db/backends/oracle/base.py", line 497, in execute
return self.cursor.execute(query, self._param_generator(params))
django.db.utils.DatabaseError: ORA-00910: specified length too long for its datatype
django==2.0.4
django-advanced-filters==1.0.7.1
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/Users/sarit/.pyenv/versions/poink/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/Users/sarit/.pyenv/versions/poink/lib/python3.6/site-packages/django/core/management/__init__.py", line 347, in execute
django.setup()
File "/Users/sarit/.pyenv/versions/poink/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/sarit/.pyenv/versions/poink/lib/python3.6/site-packages/django/apps/registry.py", line 112, in populate
app_config.import_models()
File "/Users/sarit/.pyenv/versions/poink/lib/python3.6/site-packages/django/apps/config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "/Users/sarit/.pyenv/versions/3.6.4/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/Users/sarit/.pyenv/versions/poink/lib/python3.6/site-packages/advanced_filters/models.py", line 16, in <module>
class AdvancedFilter(models.Model):
File "/Users/sarit/.pyenv/versions/poink/lib/python3.6/site-packages/advanced_filters/models.py", line 23, in AdvancedFilter
related_name='created_advanced_filters', verbose_name=_('Created by'))
TypeError: __init__() missing 1 required positional argument: 'on_delete'
In Django2. Model
needs explicit definition of on_delete
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.