lukasvinclav / django-admin-numeric-filter Goto Github PK
View Code? Open in Web Editor NEWNumeric filters for Django admin
License: MIT License
Numeric filters for Django admin
License: MIT License
Any chance we can get the latest code released to PyPi?
This is related to pypa/pip#8559
Currently we get the following warning when installing with pip
DEPRECATION: django-admin-numeric-filter is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change.
A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559
Thanks for this project. I recently integrated these filter types and found that they currently don't match the style of Django 2.4.1.
I overrode the template filter_numeric_range.html with the following source:
{% load i18n %}
{% with choices.0 as choice %}
<details open>
<summary>{% blocktrans with filter_title=title %} By {{ filter_title }}{% endblocktrans %} </summary>
<form method="get" class="admin-numeric-filter-wrapper">
{% for k, v in choice.request.GET.items %}
{% if not k == choice.parameter_name|add:'_from' and not k == choice.parameter_name|add:'_to' %}
<input type="hidden" name="{{ k }}" value="{{ v }}">
{% endif %}
{% endfor %}
<div class="admin-numeric-filter-wrapper-group">
{{ choice.form.as_p }}
</div><!-- /.filter-numeric-filter-wrapper-group -->
<button type="submit" class="submit">{% trans 'Apply' %}</button>
</form>
</details>
{% endwith %}
As you can see the "summary" and "details" elements are present. Mind the spaces before/after the summary text content.
Unfortunately, collapsing works but restoring after a reload not.
I think this would be a valuable addition to this plugin.
Since Django 4.0, collectstatic post-processes source maps found in js files. See this django ticket.
The file wNumb.min.js contains this:
//# sourceMappingURL=wNumb.min.js.map
However the map does not exist. So either generate the map or remove this line.
Currently this prevents everyone using ManifestStaticFilesStorage
from running collectstatic cause it crashes.
Can I set all changes and have just one APPLAY button to filter all ?
My custom slider:
class CustomSliderNumericFilter(SliderNumericFilter):
MAX_DECIMALS = 2
field = DecimalField()
Result of SliderNumericFilter choices
method:
({
'decimals': 2,
'step': 0.01,
'parameter_name': 'total_amount',
'request': <WSGIRequest: GET '/admin/base/saleorder/'>,
'min': Decimal('20.45'),
'max': Decimal('315.05'), <---
'value_from': Decimal('20.45'),
'value_to': Decimal('315.05'), <----
'form': <SliderNumericForm bound=True, valid=Unknown, fields=(total_amount_to)>
},)
max
and value_to
are correct but as you can see in form the max value is wrong. It should be 315.05
instead of 315.00
Did i miss something ?
nouislider.min.js:3 Uncaught Error: noUiSlider (11.1.0): 'range' 'min' and 'max' cannot be equal.
at Object.G [as t] (nouislider.min.js:3)
at nouislider.min.js:3
at Array.forEach (<anonymous>)
at X (nouislider.min.js:3)
at Object.Z [as create] (nouislider.min.js:3)
at admin-numeric-filter.js:6
at Array.forEach (<anonymous>)
at HTMLDocument.<anonymous> (admin-numeric-filter.js:2)
It would be nice to have the ability to format the numbers displayed on the filter UI. For example, if the numbers represent currency, or to add comma separators, etc.
we're trying to use it for annotated field but it doesn't work, says because the model doesn't have such field. Any workaround?
Hello. I want to use your number range filter, but I got error:
ImportError: cannot import name ‘ugettext_lazy’ from ‘django.utils.translation’
Hello,
after upgrading to Django 5.x I am getting errors using all the filters (e.g. SingleNumericFilter
and RangeNumericFilter
).
No matter what I input, I alwas get this error:
["“['x']” value must be a decimal number."]
where 'x' is any number I put (could be 0, 100, 1000).
Full stack:
Environment:
Request Method: GET
Request URL: .../?e=1&project_number_from=1&project_number_to=6786
Django Version: 5.0.4
Python Version: 3.11.2
Installed Applications:
['admin_numeric_filter',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'admin_auto_filters',
'mod_wsgi.server',
'artsdb',
'choices',
'import_export',
'django_select2',
'djmoney',
'smart_selects']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback (most recent call last):
File "/usr/local/py_ptracker/lib/python3.11/site-packages/django/db/models/fields/__init__.py", line 1805, in to_python
decimal_value = decimal.Decimal(value)
^^^^^^^^^^^^^^^^^^^^^^
During handling of the above exception (argument must be a sequence of length 3), another exception occurred:
File "/usr/local/py_ptracker/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
response = get_response(request)
^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/py_ptracker/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/py_ptracker/lib/python3.11/site-packages/django/contrib/admin/options.py", line 716, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/py_ptracker/lib/python3.11/site-packages/django/utils/decorators.py", line 188, in _view_wrapper
result = _process_exception(request, e)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/py_ptracker/lib/python3.11/site-packages/django/utils/decorators.py", line 186, in _view_wrapper
response = view_func(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/py_ptracker/lib/python3.11/site-packages/django/views/decorators/cache.py", line 80, in _view_wrapper
response = view_func(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/py_ptracker/lib/python3.11/site-packages/django/contrib/admin/sites.py", line 240, in inner
return view(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/py_ptracker/lib/python3.11/site-packages/import_export/admin.py", line 667, in changelist_view
return super().changelist_view(request, extra_context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/py_ptracker/lib/python3.11/site-packages/import_export/admin.py", line 872, in changelist_view
return super().changelist_view(request, extra_context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/py_ptracker/lib/python3.11/site-packages/import_export/admin.py", line 69, in changelist_view
return super().changelist_view(request, extra_context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/py_ptracker/lib/python3.11/site-packages/django/utils/decorators.py", line 48, in _wrapper
return bound_method(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/py_ptracker/lib/python3.11/site-packages/django/utils/decorators.py", line 188, in _view_wrapper
result = _process_exception(request, e)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/py_ptracker/lib/python3.11/site-packages/django/utils/decorators.py", line 186, in _view_wrapper
response = view_func(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/py_ptracker/lib/python3.11/site-packages/django/contrib/admin/options.py", line 1985, in changelist_view
cl = self.get_changelist_instance(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/py_ptracker/lib/python3.11/site-packages/django/contrib/admin/options.py", line 864, in get_changelist_instance
return ChangeList(
File "/usr/local/py_ptracker/lib/python3.11/site-packages/django/contrib/admin/views/main.py", line 144, in __init__
self.queryset = self.get_queryset(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/py_ptracker/lib/python3.11/site-packages/django/contrib/admin/views/main.py", line 547, in get_queryset
new_qs = filter_spec.queryset(request, qs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/py_ptracker/lib/python3.11/site-packages/admin_numeric_filter/admin.py", line 97, in queryset
return queryset.filter(**filters)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/py_ptracker/lib/python3.11/site-packages/djmoney/models/managers.py", line 207, in wrapper
queryset = func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/py_ptracker/lib/python3.11/site-packages/django/db/models/query.py", line 1476, in filter
return self._filter_or_exclude(False, args, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/py_ptracker/lib/python3.11/site-packages/django/db/models/query.py", line 1494, in _filter_or_exclude
clone._filter_or_exclude_inplace(negate, args, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/py_ptracker/lib/python3.11/site-packages/django/db/models/query.py", line 1501, in _filter_or_exclude_inplace
self._query.add_q(Q(*args, **kwargs))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/py_ptracker/lib/python3.11/site-packages/django/db/models/sql/query.py", line 1613, in add_q
clause, _ = self._add_q(q_object, self.used_aliases)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/py_ptracker/lib/python3.11/site-packages/django/db/models/sql/query.py", line 1645, in _add_q
child_clause, needed_inner = self.build_filter(
File "/usr/local/py_ptracker/lib/python3.11/site-packages/django/db/models/sql/query.py", line 1559, in build_filter
condition = self.build_lookup(lookups, col, value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/py_ptracker/lib/python3.11/site-packages/django/db/models/sql/query.py", line 1389, in build_lookup
lookup = lookup_class(lhs, rhs)
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/py_ptracker/lib/python3.11/site-packages/django/db/models/lookups.py", line 30, in __init__
self.rhs = self.get_prep_lookup()
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/py_ptracker/lib/python3.11/site-packages/django/db/models/lookups.py", line 88, in get_prep_lookup
return self.lhs.output_field.get_prep_value(self.rhs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/py_ptracker/lib/python3.11/site-packages/django/db/models/fields/__init__.py", line 1829, in get_prep_value
return self.to_python(value)
^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/py_ptracker/lib/python3.11/site-packages/django/db/models/fields/__init__.py", line 1807, in to_python
raise exceptions.ValidationError(
^
Exception Type: ValidationError at /admin/artsdb/project/
Exception Value: ["“['1']” value must be a decimal number."]
Maybe similar to how GeoModelAdmin works:
@property
def media(self):
"Injects OpenLayers JavaScript into the admin."
return super().media + Media(js=[self.openlayers_url] + self.extra_js)
In the short term you should mention in the install docs that the current recommended way to do things will break other stuff.
@lukasvinclav filter widget not displayed when used with Django JET theme package. Is it not supported yet ?
But actual is 0.1.7
I have a collection of entities with a value that can have value 0, and would wish to filter them using this utility. However, when one has value 0, the slider disappears and says there's not enough data. In the example shown below, if I change the second entity's "Coste de ingeniería" value to any positive value, the filter works as intended.
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.