On Dec 15, 2003, at 18:26, Guenther Starnberger wrote:
> some time ago there was a thread on this mailinglist, about overiding
> the
> new() method in classes inherited from SQLObject.
> (http://thread.gmane.org/gmane.comp.python.sqlobject/906)
>
> according to a posting in this thread it is possible to call the
> 'original'
> SQLObject new() method by: 'SQLObject.new(cls, **kw)'.
>
> but somehow this doesn't work for me :/
>
> class Account(SQLObject):
> __name = StringCol(alternateID = True)
> __password = StringCol()
>
> __def new(cls, **kw):
> ____print "FOO"
> ____SQLObject.new(cls, **kw)
>
> __new = classmethod(new)
I started that thread. Which version of Python are you using? Turns out
that there is a bug in the classmethod code that causes inheritance
problems in Python < 2.2.3 (I think, can't quite remember now). That
was one problem.
I override new as follows:
def new(cls, **kw):
"""
Overrides class method .new() to automatically add mandatory
sections to request object
"""
obj = super(Request, cls).new(**kw)
return obj
new = classmethod(new)
...Edmund.
|