shinneider / django-admin-search Goto Github PK
View Code? Open in Web Editor NEWModal filter for django admin
License: MIT License
Modal filter for django admin
License: MIT License
in the version 0.3.2
I added some tests, but the core django_admin_search/admin.py
is not tested yet, need to cover this.
to elaborate test cases for this can be tricky.
The most recent release on PyPI (3.11
, untagged here on GitHub) doesn't include the most recent commits from January which are required for compatibility with Django 4. Please release a version 3.12
on PyPI!
(In the meantime, anyone wanting to use this with Django 4 -- or silence the deprecation warnings with Django 3 -- can use pipenv install -e git+https://github.com/shinneider/django-admin-search@47245d8#egg=django-admin-search
or similar.)
In example folder, has a requirements.txt
with django==2.2.4
.
because of this, if community encoutered a new bug in this version, dependabot create a PR and a alert for me.
however is a example folder, i need to remove this, because is not a critical erro, example folder is not lib package.
I suggest change requirements to wildcard version in minor and patch ex: django==2.*
django_admin_search/utils.py
from decimal import Decimal
if isinstance(value, forms.DecimalField):
return Decimal(key_value)
With this commit:
86463f7#diff-87b0e17e051db518901ad65521b336894bf5652a42e5fc1f8e6ffea9896b8930
Method get_field_override was renamed into get_field_value, but there is already get_field_value on a class with a completely different signature, this makes the code explode with message: "Filter not applied, error has occurredget_field_value() missing 4 required positional arguments: 'form_field', 'field_value', 'has_field_value', and 'request'"
jquery
and jquery mask
is not using a minified version.
because of that, the lib has size of 400kb, but 386kb is static js files.
Changing for minified, lib size decrese +/- 300kb.
Hello! In Django 3.0, {% load admin_static %}
was removed in favour of {% load static %}
(see the second last point of https://docs.djangoproject.com/en/dev/releases/3.0/#features-removed-in-3-0)
Could this package update django_admin_search/templates/admin/custom_change_list.html and https://github.com/shinneider/django-admin-search/blob/90e382e01c95d0f79a2381b5fc580a851494f6af/django_admin_search/templates/admin/custom_search_form.html to be compatible? Thanks!
not getting the parameters GET correctly
Hi,
i currently updated to django-admin-search 0.3.8
and tried building my Container after that. It gets me following error:
#18 19.18 Downloading django-admin-search-0.3.8.tar.gz (49 kB)
#18 19.19 Preparing metadata (setup.py): started
#18 19.70 Preparing metadata (setup.py): finished with status 'error'
#18 19.70 ERROR: Command errored out with exit status 1:
#18 19.70 command: /usr/local/bin/python -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-u2gyywqj/django-admin-search_6ace2ea415234adeb9a255046aacca76/setup.py'"'"'; __file__='"'"'/tmp/pip-install-u2gyywqj/django-admin-search_6ace2ea415234adeb9a255046aacca76/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-1m8huu2c
#18 19.70 cwd: /tmp/pip-install-u2gyywqj/django-admin-search_6ace2ea415234adeb9a255046aacca76/
#18 19.70 Complete output (7 lines):
#18 19.70 Traceback (most recent call last):
#18 19.70 File "<string>", line 1, in <module>
#18 19.70 File "/tmp/pip-install-u2gyywqj/django-admin-search_6ace2ea415234adeb9a255046aacca76/setup.py", line 7, in <module>
#18 19.70 from django_admin_search.meta import VERSION
#18 19.70 File "/tmp/pip-install-u2gyywqj/django-admin-search_6ace2ea415234adeb9a255046aacca76/django_admin_search/__init__.py", line 2, in <module>
#18 19.70 from django import __version__ as django_version
#18 19.70 ModuleNotFoundError: No module named 'django'
#18 19.70 ----------------------------------------
#18 19.70 WARNING: Discarding https://files.pythonhosted.org/packages/4c/6b/3603e90207855c7414386c20d0662f6a6a2ad18e6441a70f00c6614750b6/django-admin-search-0.3.8.tar.gz#sha256=f1b248b5e1706a75e64597b3eb21efd212576ac06eaec608bb0633e112b0d911 (from https://pypi.org/simple/django-admin-search/) (requires-python:>=3.3). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
#18 19.70 ERROR: Could not find a version that satisfies the requirement django-admin-search==0.3.8 (from versions: 0.1.1, 0.2.2, 0.3, 0.3.1, 0.3.3, 0.3.5, 0.3.6, 0.3.7, 0.3.8)
#18 19.70 ERROR: No matching distribution found for django-admin-search==0.3.8
i moved django before django-admin-search in the requirements.txt but it didn't help.
This is my command for pip pip install -r requirements.txt --no-cache-dir
Do you have an idea what i could do here?
Best Regards
Fabian
Package generated by python setup.py sdist
contains a test folder inside, but is not necessary for work, i want to remove this.
I want to refactor advanced_search_query
function inside django_admin_search/admin.py
Because is a very large function, is hard to maintenance and developer test cases.
This function is responsible for:
- allow to create a custom filter for especific field (line 63 to 71)
- get field and filter method (73 and 74)
- apply default filter (76 to 92)
I sugeste create a specific function for all this methods.
currently, after applying the filter and opening the modal again, it is empty, should keep the value of the filters.
The static
folder should have a subfolder named django_admin_search
to avoid conflicting with already existing static files when running python manage.py collectstatic
.
Diff to easy simulate erro
--- a/example/app/example/admin.py
+++ b/example/app/example/admin.py
@@ -11,6 +11,7 @@ from .models import Area
class AreaAdmin(AdvacedSearchAdmin):
form = AreaForm
search_form = AreaSearchForm
+ list_per_page = 1
Create a 2 or more entries, after this change for another page (other than the first), and try to user advanced filter modal, nothing happens. not filters applied no errors in browser console or python.
Currently checkbox field has no format (css styles), however all other field are be formatted, i suggest format this field too.
But no have ideia for this field format
Simple stylized checkbox ?
Toggle field format ?
Transform in select field with options True and False ?
The method definition should have the following parameters:
def search_FieldNameHere(request, field_value, param_values):(self, field, field_value, form_field, request, advanced_search_fields)
Pagination does not carry filter parameters.
Input filter parameters
http://127.0.0.1:8000/admin/reports/tpareports/?date_start=2012-09-26&date_end=2028-09-26
Pagination is still original
OS: Windows 10/Alpine Linux v3.13
Python version 3.6
Django version 3.1.3
django-admin-search version 0.3.11
Browser Chrome
This plugin is great. I can't fix it because I'm a Django beginner.
I appreciate your contribution whether you fix this or not.
Once the search is over, the page doens't refresh to return back the original set of records. Please check the url even after we remove the parameters, we don't get the original expected rows in the modeladmin view, until we make some changes in the python code and save it.
if your django admin use pagination, and your change the page, all advanced search params is lost.
If a ChoiceField
is added to the search form, when the search is made, the choice field always gets into the queryset with the first value as default selected.
It is not always necessary that the search should include the value from the ChoiceField.
It is possible to allow empty
or null
value to the Choice field and it should be added to the queryset if is not null?
Login based queryset object to be returned.
Since this tool overrides the default django queryset object already, how to return the only customer domain based specific records as default , when not searched.
eg: ```
def get_queryset(self, request):
domain_list = []
temp = []
qs = super(LogSearchFormAdmin, self).get_queryset(request)
if request.user.is_superuser:
return qs
else:
domain_list = Domain.objects.filter(
customer__in=Customer.objects.filter(
email=request.user.username)).values_list(
'name', flat=True)
#print(list(domain_list))
dom_names = list(domain_list)
#print(dom_names)
qs = MailLogs.objects.none()
if dom_names:
for d in dom_names:
qs = MailLogs.objects.filter(
Q(mfrom__icontains=d)|Q(mto__icontains=d))
# qs |= MailLogs.objects.filter(mfrom__icontains=d)
# qs |= MailLogs.objects.filter(mto__icontains=d)
print(qs.query)
#print(qs)
return qs
Hi,
There are two issues:
__contains
in CharField
.Example:
#models.py
class Emp(models.Model):
first_name = models.CharField(blank=False, null=False, max_length=100)
last_name = models.CharField(blank=True, null=True, default=None, max_length=100)
#search form
class EmpSearchForm(forms.Form):
first_name = forms.CharField(
required=False,
widget=forms.TextInput(
attrs={
'filter_method': '__contains',
}
)
)
last_name = forms.CharField(
required=False
)
If we want to filter only by first_name
. The filter does not return any result when the value of last_name
is null
.
If we want to filter only by first_name
, then the above search form does not return any result because last_name
's filter_method
is not set to __contains
. The generated URL is:
emp/?first_name=John&last_name=
Setting last_name
's filter_method
to __contains
will work fine.
last_name = forms.CharField(
required=False,
widget=forms.TextInput(
attrs={
'filter_method': '__contains',
}
)
)
suggestion:
emp/?first_name=John&last_name=
filter should work only on first_name
as the last_name
is empty so it should be ignored.currently all fields occupy 100% of the line, I suggest having field options occupying only half the line (for accept two field by line).
in this issue is interesting to improve the spacing between label and field also.
The file django_admin_search/templates/admin/custom_fieldset.html
is responsable by field html, to find css follow the issue 22 .
Apply selecting few filters and applying it, there is no way to go back and clear the filters.
In the file django_admin_search/templates/admin/custom_search_form.html
has many lines of css.
i need to move this lines of css, to a external css file, loaded in the html
according pip (https://pypi.org/classifiers/)
Each project's maintainers provide PyPI with a list of "trove classifiers" to categorize each release, describing who it's for, what systems it can run on, and how mature it is.
These standardized classifiers can then be used by community members to find projects based on their desired criteria.
Unable to use search_Field right now. Trying using django 3.0.5
I'd like to use the tool with Django 4, but url has been deprecated.
I found this issue https://stackoverflow.com/questions/70319606/importerror-cannot-import-name-url-from-django-conf-urls-after-upgrading-to, which suggests to replace url
with re_path
from from django.urls import re_path
.
This is a grammatical error, it needs to be corrected
Files to be changed:
README.md
Line(s) -> 48, 53, 92, 97
django_admin_search/admin.py
Line(s) -> 9
django_admin_search/templates/admin/custom_search_form.html
Line(s) -> 69, 103, 135
example/app/example/admin.py
Line(s) -> 4, 11
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.