Hi,

There's probably a better way, but I would do like the code they use
in the admin, something like:
# 'query' is the query you want to run. It can be, for instance, "WLAN john"
or_query=Q()
search_fields = ['articles','author'] # and whatever field of the
articles you want to search
if query:
    for bit in query.split():
        or_queries = [models.Q(**{'%s__icontains' % field_name: bit})
for field_name in search_fields]
        other_qs = QuerySet(self.model)
        other_qs = other_qs.filter(reduce(operator.or_, or_queries))
return other_qs

Again, I borrowed (copied...) this code from one of the admin views,
and it works pretty well for me. But there's probably better way of
doing that.

Enjoy,

G

On 6/26/06, Kristoffer <[EMAIL PROTECTED]> wrote:
>
>
> I have a simple Django application that displays articles.
> Now, I would like to let my users search the articles for key words,
> and I found this topic from this group:
> http://groups.google.com/group/django-users/browse_thread/thread/e5e82d81b0b85aa7/b06b72997a6a1e0c
>
> Is this still the way to go if I would like to add basic search
> functionality?
> I have django 0.91 installed (using 'emerge' on my Gentoo Linux box).
> Do I need to install "stuff" or "AbstractSearching" manually (fetching
> it with svn) for this to work? In that case, where do I put the files?
>
> Thanks for any input,
> Kristoffer
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to