Am 18.07.2010 um 21:16 schrieb Timuçin Kızılay:
Mengu yazmış:
doesn't this help?:
def __init__(self, a, b, c):
self.a = a
self.b = b
self.c = a + b
On 18 Temmuz, 18:00, Timuçin Kızılay <[email protected]>
wrote:
I've read the documentation but could not find it so I'm asking
here.
I have a table in models and there is a column in that model that
it's
value shuld be changed when there is an insert or update on that
table.
here is an example:
-----------
class Sometable(DeclarativeBase):
__tablename__ = 'sometable'
id = Column(Integer, autoincrement=True, primary_key=True)
a = Column(Unicode(50))
b = Column(Unicode(50))
c = Column(Unicode(100))
-------
in that table, I want only set the values of a and b and value of c
should be c = a + b
I think I should write a function but where should I put that
function?
it helps only when creating a new record but not updating or setting
the fields like this.
-------------------------------
somerecord = model.SomeTable()
somerecord.a = 'something'
somerecord.b = 'otherthing'
model.DBSession.add(somerecord)
-------------------------------
I need to write some function that should run when a record updated
or inserted to set other fields depending of some fields.
I don't know anything about declarative, but for me that sounds like a
job for properties. In Elixir, I'd roughly do it like this:
class Sometable(Entity):
_a = Column(Unicode, name="a")
_b = Column(Unicode, name="b")
_c = Column(Unicode, name="c")
@apply
def a():
def fget(self):
return self._a
def fset(self, value):
self._a = value
self._c = value + self._b
return property(**locals())
... # also with b
It might be that both declarative and elixir support defining property
setter and getter functions directly, but I don't know that out of my
head.
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.