I have a search function on my site.
A user needs to be able to input multiple words that are then searched
for in multiple text fields. My issue is the following: my function
works very well for a single word or for the last word of a search as
the queryset gets overwritten. I understand what is going on. What I
don't get is what to do about it. I can concatenate querysets by
casting them explicitly as lists; However I can't cast back to a
queryset so that I can use  generic list view. Any ideas? I know this
is such a common thing that it must have been done before by someone.

Appreciate any answers;

Hajo Smulders

Here is the view function:

def recipe_search(request, searchcriteria, sorter, page):
    BASE_ROOT = determine_baseroot() # don't worry about this, this
sets the different environments I work in (IE: different URLs for
developemnt, QA and prod
    searchcriteria = searchcriteria.split(" ") # This allows multiple
inputs
# I'm chceking one field (main_ingredients first; only if I don't get
any results do a do a full text search on the other fileds
    for criterion in searchcriteria:
        tempquery =
Recipe.objects.filter(main_ingredients__icontains=criterion)
    if tempquery.count() < 1:
        for criterion in searchcriteria:
            tempquery =
Recipe.objects.filter(Q(ingredients__icontains=criterion) |
Q(description__icontains=criterion) |
Q(instructions__icontains=criterion))
    recipequery = tempquery.order_by(sorter)
    return list_detail.object_list(
        request,
        queryset = recipequery,
        template_object_name = "recipe",
        paginate_by = 20,
        page=page,
        allow_empty = True,
        extra_context = {
            "baseroot" : BASE_ROOT,
        }
)


--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to