Just for the archive,
On 08/02/2012 16:47, Michael Bayer wrote:
@hybrid_property
def namesandvar(self):
nVar = self.name
if self.name2:
nVar += ', ' + self.name2
if self.variety:
nVar += ', ' + self.variety
return nVar
I must be doing something wrong when defining my "NAMES40" custom type as when
I change it to use Unicode the query works fine.
those + signs should probably be concatenation operators. You'll get concatenation as
long as the type of column includes "types.Concatenable" in its inheritance
hierarchy.
Went "back" to using straight sa.Unicode instead of my customtype and
changed the hybrid_property to the following:
@hybrid_property
def namesandvar(self):
if not self.variety in [None, u'']:
return self.drinknames + u", " + self.variety
else:
return self.drinknames
@namesandvar.expression
def namesandvar(cls):
return case([
(cls.variety != None, cls.drinknames + u", " + cls.variety),
], else_ = cls.drinknames)
Which is based on what I found in the doc here:
http://docs.sqlalchemy.org/en/latest/orm/mapper_config.html#mapper-sql-expressions
Werner
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.