django-admin-search
django-admin-search copied to clipboard
Issue in filtering the attributes with null value.
Hi, There are two issues:
- There is an issue in filtering the attributes with null value.
- Always need to include
__containsinCharField.
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 oflast_nameisnull. -
If we want to filter only by
first_name, then the above search form does not return any result becauselast_name'sfilter_methodis not set to__contains. The generated URL is:emp/?first_name=John&last_name=Setting
last_name'sfilter_methodto__containswill work fine.last_name = forms.CharField( required=False, widget=forms.TextInput( attrs={ 'filter_method': '__contains', } ) )
suggestion:
- We can ignore the filter whose value is not passed or empty in the query parameter.
e.g., for
emp/?first_name=John&last_name=filter should work only onfirst_nameas thelast_nameis empty so it should be ignored.
Hi @kunal-8 now i have little time, to maintain this library, i you have time, please create a PR.
I believe that it is better to change the method django_admin_search.utils.get_field_value_default.
or set has_field_value to false, if value is empty...
@shinneider Please check the pull request https://github.com/shinneider/django-admin-search/pull/49 which fixes this issue.
@anuj-scanova PR accepted, please, test on v0.3.13, i created today on pypi