I'm trying to get my filter working but am having trouble with a specific
field in my table. I'm trying to filter by 'formulatedById' which is a
ForeignKey in my class/table. Here is the class def in my model.
class Formula(SQLObject):
class sqlmeta:
style = Style(longID=True)
idName = 'formulaId'
plant = ForeignKey('Plant', dbName='plantId')
fPlant = StringCol(length=15)
qPlant = StringCol(length=15)
name = StringCol(length=50)
description = UnicodeCol(length=255)
dateStored = DateCol()
cost = CurrencyCol()
formulatedBy = ForeignKey('User', dbName='formulatedById')
productClass = ForeignKey('ProductClass', dbName='productClassId')
productGroup = ForeignKey('ProductGroup', dbName='productGroupId')
price = CurrencyCol()
createdOn = DateCol()
I'm doing the following:
f = Formula.select()
f = f.filter(Formula.q.name.startswith(searchText.encode('utf8')))
f = f.filter(Formula.q.formulatedBy==18)
And I get the following on the last statement.
AttributeError: Formula instance has no attribute 'formulatedBy'
Can someone tell me what is causing this error and how I can reference this
field in my filter?
Again, I appreciate any info you can give me.
-Jim
-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Jorge Godoy
Sent: Friday, January 12, 2007 6:10 PM
To: [email protected]
Subject: [TurboGears] Re: Dynamic SQL Help
"Diez B. Roggisch" <[EMAIL PROTECTED]> writes:
> No deal. Just do stuff like this (for example of course):
>
> whereClauses = []
>
> if condition:
> whereClauses.append(Model.q.someProp == someValue)
> if other_condition:
> whereClauses.append(Model.q.someOtherProp == someOtherValue)
>
> if whereClauses:
> return Model.select(AND(*whereClauses))
> else:
> return Model.select()
Using the filter method looks a lot cleaner to me... And easier to see what
is happening.
--
Jorge Godoy <[EMAIL PROTECTED]>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---