Re: filter like __icontains

101 views
Skip to first unread message

Sergiy Kuzmenko

unread,
Dec 10, 2012, 11:24:08 AM12/10/12
to django...@googlegroups.com
You should be able to do this:

class ProductFilter(django_filters.FilterSet):
    name = django_filters.NumberFilter(lookup_type='icontains')

See the docs for details: https://django-filter.readthedocs.org/en/latest/usage.html

- Sergiy


On Mon, Dec 10, 2012 at 8:34 AM, marlène gratigny <marlene....@gmail.com> wrote:
Hello,
First thank you very much for django-filters, it's a very useful tool.
I trying to make a filter on a field with a keyword, not the complete information into a field. With django,  i do that with __icontains. Can I do the same filter with django-filters?
If yes, can you explain me how to do that?
Thanks for your help
Best regards



Alessandro Dentella

unread,
Dec 10, 2012, 10:49:24 AM12/10/12
to django...@googlegroups.com
On Mon, Dec 10, 2012 at 05:34:57AM -0800, marl�ne gratigny wrote:
> Hello,
> First thank you very much for django-filters, it's a very useful tool.
> I trying to make a filter on a field with a keyword, not the complete
> information into a field. With django, i do that with __icontains. Can I do
> the same filter with django-filters?
> If yes, can you explain me how to do that?
> Thanks for your help

Suppose your field is named 'keywords', I guess you need something like:

class MyFilterset(django_filters.Filterset):

keyword = django_filters.CharField(lookup_type='icontais')
class Meta:
model = YourModel
fields = ['keywords']

Aleternatively you can add to MyFilterset:

def __init__(self, *args, **kwargs):
django_filters.FilterSet.__init__(self, *args, **kwargs)
self.filters['keywords'].lookup_type = 'icontains'



sandro
*:-)


--
Sandro Dentella *:-)
http://www.reteisi.org Soluzioni libere per le scuole
http://sqlkit.argolinux.org SQLkit home page - PyGTK/python/sqlalchemy



marlène gratigny

unread,
Dec 11, 2012, 3:29:53 AM12/11/12
to django...@googlegroups.com, san...@e-den.it
Thank you very much everybody.

On Monday, 10 December 2012 16:49:24 UTC+1, Alessandro Dentella wrote:
Reply all
Reply to author
Forward
0 new messages