adam schrieb:
> well this is what i have come up with
> 
> forename = DBSession.query(AddressBookContact).filter(or_
> (AddressBookContact.contact_forename.like('%'+str(kw['info'])+'%'),
>         AddressBookContact.contact_surname.like('%'+str(kw['info'])
> +'%'),
>         AddressBookContact.contact_email.like('%'+str(kw['info'])
> +'%'),
>         AddressBookContact.contact_address1.like('%'+str(kw['info'])
> +'%'),
>         AddressBookContact.contact_address2.like('%'+str(kw['info'])
> +'%'),
>         AddressBookContact.contact_street.like('%'+str(kw['info'])
> +'%'),
>         AddressBookContact.contact_town.like('%'+str(kw['info'])+'%'),
>         AddressBookContact.contact_county.like('%'+str(kw['info'])
> +'%'),
>         AddressBookContact.contact_postcode.like('%'+str(kw['info'])
> +'%'),
>         AddressBookContact.contact_country.like('%'+str(kw['info'])
> +'%'),
>         AddressBookContact.contact_telephone.like('%'+str(kw['info'])
> +'%'),
>         AddressBookContact.contact_mobile.like('%'+str(kw['info'])
> +'%'))).filter(AddressBookContact.system_website == website[0]).all()
> 
> it seems like a lot to search one table of information. Is this the
> most sufficient way to search?

Certainly not, as it is highly repetive. you do the same stuff over and 
over, so you can optimize:

search_string = "%%%s%%" % str(kw['info'])

clause = []
abc = AddressBookContact
for column in (abc.contact_surname, abc.contact_email, ...):
     clause.append(column.like(search_string))

forename = DBSession.query(AddressBookContact).filter(or_(*clause)). # 
the rest.

But in the end, if you want to search many fields, you'll need a clause 
that encompasses them. So the resulting SQL would be equivalent.

Diez

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" 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/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to