Hi there.

I am trying to make a search function.

                                lookupInt1 = 1
                                print "inden loekke"
                                for i in fromCityList:
                                        print "test"+ i.by
                                        if lookupInt1 == numberOfCitiesFrom:
                                                lookupString = lookupString + 'Q
(start_address__city__istartswith="'+ i.by +'"),'
                                        else:
                                                lookupString = lookupString + 'Q
(start_address__city__istartswith="'+ i.by +'")|'
                                        lookupInt1 = lookupInt1 + 1
                                lookupString = lookupString + "Q
(ride_date__gte=now)"
                                rideListExtra = 
Ride.objects.filter(lookupString)

Since i do not know how many objects are in my fromCityList it is hard
for me to do a normal filtering lookup.
Therefore i want to create the lookup string as a variable and then
use that for the db lookup.
But it doesn't work :-(
I get the exception: too many values to unpack

But i know the "code" in the string works. I can print 'lookupString'
in the terminal and copy/paste this to a new variable like this:
                                                                testList = 
Ride.objects.filter(Q
(start_address__city__istartswith="Esbjerg")|Q
(start_address__city__istartswith="Bramming"),Q(ride_date__gte=now))

Now it works like it should, but then i can't change the number of
objects in the fromCityList.

I hope you understand my problem: I want to use a custom made string
as a query lookup string. Is this possible??


Pete
--~--~---------~--~----~------------~-------~--~----~
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