Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
How to use a string in filter()
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
M.Ganesh  
View profile  
 More options May 17 2008, 12:13 pm
From: "M.Ganesh" <ganeshpuls...@gmail.com>
Date: Sat, 17 May 2008 07:43:51 +0530
Local: Sat, May 17 2008 12:13 pm
Subject: How to use a string in filter()
Hi All,

I am back with another query

I have this (generic) view function

--------------------------8><------------------------------------
def object_list(request, object, filter_string = None):
    if filter_string:
        object_list = object.objects.filter(filter_string)
    else:
        object_list = object.objects.all()

    return render_to_response(object.__name__ + '_list.html',
                              {object.__name__ + '_list': object_list},
                              RequestContext(request))
--------------------------8><------------------------------------

Now this function works when I don't pass on the filter_string, and I
get the entire object list. But when I pass on a value for filter_string
(say 'entity=2') I get this error :

'unicode' object has no attribute 'get_sql'

How do I pass strings to filter_string and get a filtered object list?

Thanks in advance

Ganesh


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
caustic  
View profile  
 More options May 17 2008, 9:59 pm
From: caustic <ste...@gmail.com>
Date: Sat, 17 May 2008 04:59:22 -0700 (PDT)
Local: Sat, May 17 2008 9:59 pm
Subject: Re: How to use a string in filter()

On May 17, 9:13 am, "M.Ganesh" <ganeshpuls...@gmail.com> wrote:

You cannot. You should pass either an instance of django.db.models.Q
or a set of keyword arguments.
This means you should change code in the object_list caller to do
something like this:

object_list(request, model.Object, Q(entity=2))


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
M.Ganesh  
View profile  
 More options May 18 2008, 1:40 am
From: "M.Ganesh" <ganeshpuls...@gmail.com>
Date: Sat, 17 May 2008 21:10:33 +0530
Local: Sun, May 18 2008 1:40 am
Subject: Re: How to use a string in filter()

Hmm. I'll have to read about Q objects...

Thanks for the pointer

Regards Ganesh


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google