Yes - sorry about the typo.  As you say, the "orig" should be
filter_orig - that was a cut and paste mistake.

I was playing around and I think I just mistakenly assumed that I
could create a Q from the string representation of another Q.   Sounds
like that was a mistaken assumption.

What I have is a string representation that is a prefix notation that
is very similar to what you get when you print a Q.  IE, it is easy
for me to generate something like this:

(OR (AND: ('owner__username', 'mlevine'), ('status', 'open')),
('priority', 'critical'))

Where this means (Q(owner_username='mlevine') & Q(status='open')) | Q
(priority='critical')

Actually, what I have is just plain xml.  Through basic regexp
substitution I am able to turn it into the above prefix notation with
minimal effort.

So I was trying to figure out if there was a way I could easily create
a Q without loading my prefix notation into a tree and recursing into
the tree to create the Q from the leaves up.  I was pleasantly
surprised when I was able to construct a Q off of the string rep of
another Q, but it looks like that it is not really doing what I
thought it was doing.  Ok, back to the drawing board.

Margie




On Jul 22, 5:02 am, Russell Keith-Magee <freakboy3...@gmail.com>
wrote:
> On Wed, Jul 22, 2009 at 5:52 AM, Margie<margierogin...@yahoo.com> wrote:
>
> > I have a situation where I want to do the following:
> >       take a bunch of POST params and from them create a Q object
> >       urlencode that Q object and turn it into a GET param, redirect
> > using that param
> >       process the GET that contains the urlencoded Q object, create a
> > Q object from it, and use it in a filter
>
> > I think this should all be possible, however, I am having trouble
> > recreating the new Q object from the string representation of the
> > original Q object. Here's an example of the problem:
>
> >>>> filter_orig = Q(owner__username='mlevine')
> >>>> print filter_orig
> > (AND: ('owner__username', 'mlevine'))
> >>>> filter_new = Q("%s" % orig)
>
> This is the line that looks a bit suspect to me. Firstly - I'm
> assuming `orig` should actually be `filter_orig` - in which case...
>
> >>>> print filter_new
> > (AND: (AND: ('owner__username', 'mlevine')))
>
> This isn't quite what you think it is. You are reading it as an AND
> whose first term is an AND. I suspect what you are actually getting is
> an AND clause whose first term is a string that starts "(AND:"
>
> When you construct filter_new, you don't pass in a string - you're
> passing in a dictionary of kwargs. The owner__username='mlevine'
> syntax is a keyword argument, not a string.
>
> Your original problem descriptions seems to suggest that you think you
> will be able to pass a string into Q() and have it interpreted as a
> query. This isn't the case - the arguments to Q() are no different to
> the arguments to filter(). If you want to serialize a query for use in
> a GET request, you'll need to find a different way to serialize your
> query.
>
> Yours,
> Russ Magee %-)
--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to