From: <mar...@ge...> - 2004-03-02 22:12:29
|
I am new to Python and SQLObject and I am looking for tips on how to do a search in a web application that uses SQLObject. For testing/learning purposes I am using the Person class from the SQlObject: from SQLObject import * class Person(SQLObject): _connection = MySQLConnection(host='localhost', db='test', user='*', passwd='*', debug=1) firstName = StringCol(length=100) middleInitial = StringCol(length=1, default=None) lastName = StringCol(length=100) So far I have a findPerson method that looks like this: def findPerson(self, id, fn, mi, ln): persons = Person.select( AND(Person.q.firstName.startswith(fn), Person.q.middleInitial.startswith(mi), Person.q.lastName.startswith(ln))) return persons Where id, fn, mi and ln are the values of the fields in my search form - not very impressive and problematic in many ways I know ! What I would like is to implement a findPerson method that, based on the field values incl. any operators - *, <, >, <=, >= and so on, is able to perform a proper search and return all matching Person objects(rows). I have fiddled around with some inelegant string substitution to ugly to post. Especially properties - in this case middleInitial - that defaults to None, are troublesome, since an empty field is not matched by None. Is there a elegant preferably generic solution for the above ? by generic I mean somthing that would work irrespective of the specific class. I am using Python 2.3 on Windows 2000 and SQLObject 0.5.1. Ian Bicking - super cool tool. Regards, Martin ------------------------------------------------- WebMail fra Tele2 http://www.tele2.dk ------------------------------------------------- |