Thank you for replying me
I tried flatpages =
FlatPage.objects.filter(Q(title__contains=search_str) |
Q(content__contains=search_str))
products = Product.objects.filter(Q(title__contains=search_str) |
Q(description__contains=search_str))
but it gave me error
Exception Type: NameError
Exception Value: global name 'Q' is not defined
If you can help me and tell what is the right syntax i ould really
appreciate that a lot
Thank you in advance
Mary Adel
On Feb 23, 1:37 pm, "Aidas Bendoraitis" <aidas.bendorai...@gmail.com>
wrote:
> Just filter searchable models according the searchable fields by the
> user-input. You'll need a form with a field forsearchstring. And a
> view for results with something like:
> flatpages = FlatPage.objects.filter(Q(title__contains=search_str) |
> Q(content__contains=search_str))
> products = Product.objects.filter(Q(title__contains=search_str) |
> Q(description__contains=search_str))
> ... if consider that the visitor cansearchin title and content of
> flat pages and in title and description of products.
> To make thesearcheven more flexible, you can parse the search_str
> into chunks considering that spaces react as OR operators (like in the
> popularsearchengines) and then to form some complex filter arguments
> and pass them to the filter method using *args and **kwargs, like this
> flatpage_args = ... # OR'ed arguments
> flatpage_kwargs = ... # arguments to AND
> flatpages = FlatPage.objects.filter(*flatpage_args, **flatpage_kwargs)
> product_args = ... # OR'ed arguments
> product_kwargs = ... # arguments to AND
> products = Product.objects.filter(*product_args, **product_kwargs)
> Regards,
> Aidas Bendoraitis [aka Archatas]
> On 2/22/07, Mary <madelghat...@gmail.com> wrote:
> > How can i add asearchfeature to my website?
> > Can anybody help me in this
> > Thank you in advance;
> > Mary Adel