I would apply a single event listener to Temporal, and do all the work of adding the constraints and all that in the one event handler. I'd skip __table_args__.
If you're on 0.8, you can apply listeners to mixins and unmapped classes using "propagate=True", and the events should trigger for all subclasses. On May 23, 2013, at 7:49 AM, Chris Withers <ch...@simplistix.co.uk> wrote: > Hi All, > > I have a mixin defined like this: > > def add_exclude_constraint(mapper, class_): > table = class_.__table__ > elements = [('period', '&&')] > for col in table.primary_key.columns: > if col.name!='period': > elements.append((col, '=')) > table.append_constraint(ExcludeConstraint(*elements)) > > class Temporal(object): > > @declared_attr > def __table_args__(cls): > listen(cls, 'instrument_class', add_exclude_constraint) > return ( > CheckConstraint("period != 'empty'::tsrange"), > ) > > period = Column(DateTimeRange(), nullable=False, primary_key=True) > > That listen call is the source of the dirty feeling... > > What's the "right" way to do this? > > Chris > > -- > Simplistix - Content Management, Batch Processing & Python Consulting > - http://www.simplistix.co.uk > > -- > 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 sqlalchemy+unsubscr...@googlegroups.com. > To post to this group, send email to sqlalchemy@googlegroups.com. > Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. > For more options, visit https://groups.google.com/groups/opt_out. > > -- 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 sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.