the columns come out in order because they have a "creation order" counter 
running that tracks the order in which each object was created.    There's 
nothing like that built into @declared_attr, I guess if it produces an object 
reference we could add the creation counter to it as well.

On Apr 25, 2013, at 4:57 AM, Chris Withers <ch...@simplistix.co.uk> wrote:

> Hi All,
> 
> I didn't see anything in the code that could help here (except maybe 
> __declare_last__, but that looks like something else) but thought I'd ask in 
> case I'm missing something...
> 
> So, some of my mixins include columns that logically come later than the 
> columns defined in the class using the mixin, eg:
> 
> class Temporal(object):
> 
>    value_from = Column(DateTime(), nullable=False, index=True)
>    value_to = Column(DateTime(), nullable=False, index=True)
> 
>    @declared_attr
>    def value_on(cls, timestamp=None):
>        if timestamp is None:
>            timestamp=datetime.now()
>        return ((cls.value_from <= timestamp) &
>                (cls.value_to > timestamp))
> 
> class Observation(Temporal, Base):
> 
>    instrument_id = Column(String(10), ForeignKey('instrument.id'), 
> primary_key=True)
>    source = Column(String(10), primary_key=True)
>    type = Column(String(10), index=True)
>    value = Column(Numeric())
> 
> The value_from and value_to columns belong at the end of the definition, but:
> 
> -> \d observation
>               Table "public.observation"
>    Column     |            Type             | Modifiers
> ---------------+-----------------------------+-----------
> value_from    | timestamp without time zone | not null
> value_to      | timestamp without time zone | not null
> instrument_id | character varying(10)       | not null
> source        | character varying(10)       | not null
> type          | character varying(10)       |
> value         | numeric                     |
> 
> Not a biggie, but curious if there's a way to get them to the end...
> 
> cheers,
> 
> 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.


Reply via email to