On Monday, July 25, 2016 at 2:29:21 PM UTC+1, Mike Bayer wrote:
>
>
>
> On 07/25/2016 09:12 AM, Michael Williamson wrote: 
> > Hello! For one of our models, I've defined a custom implementation for 
> > `__init__`. Since it should largely behave the same as the default 
> > constructor, it delegates to `_declarative_constructor`, and then runs 
> > some extra code. However, this feels like relying on some of the 
> > internals of SQLAlchemy. Is there a preferred way to implement this? 
>
> I don't think this is documented but the constructor is applied just to 
> the Base class.  So you can get to it via super: 
>
>
> class A(Base): 
>      __tablename__ = 'a' 
>      id = Column(Integer, primary_key=True) 
>      data = Column(String(50)) 
>
>      def __init__(self, foo, **kw): 
>          self.foo = foo 
>          super(A, self).__init__(**kw) 
>
>
Perfect, thanks!
 

>
>
> > 
> > Thanks 
> > 
> > Michael 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> > Groups "sqlalchemy" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> > an email to [email protected] <javascript:> 
> > <mailto:[email protected] <javascript:>>. 
> > To post to this group, send email to [email protected] 
> <javascript:> 
> > <mailto:[email protected] <javascript:>>. 
> > Visit this group at https://groups.google.com/group/sqlalchemy. 
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to