> I'm new to python and django and I'm trying to do dynamic queries.
> Can't quite get it to work right, however. This is what I'm trying to
> do.
> 
> field = "desc"
> query = User.objects.filter(  field  = "john")
> 
> but meaning `field` the variable, not the column. I don't think that
> python does that, then what do i do to get dynamic column names?

You can use dictionary keyword args[1]:

   params = {'desc': 'john'}
   query = User.objects.filter(**params)

Thus, you can build the params dictionary with whatever 
variable-names you want.

-tim

[1]
http://www.python.org/doc/current/tut/node6.html#SECTION006720000000000000000


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
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