When I try to do that I get

 File
"/home/CORP/robert.minsk/venvs/lfw/lib/python2.7/site-packages/sqlalchemy/util/_collections.py",
line 212, in __getattr__

    raise AttributeError(key)

AttributeError: hosts

On Fri, Aug 26, 2016 at 1:33 AM, Simon King <si...@simonking.org.uk> wrote:

> On Fri, Aug 26, 2016 at 2:24 AM, Robert Minsk <rmi...@gmail.com> wrote:
> > I am using automap_base to reflect a table.
> >
> > metadata = MetaData()
> > metadata.reflect(bind=engine, only=['hosts'])
> > automap = automap_base(metadata=metadata)
> > automap.prepare()
> >
> > Hosts = automap.classes.hosts
> >
> > The mac_address column in Hosts is  binary and would like to to replace
> the
> > mac_address with some sort of getter/setter to decode/encode the
> address.  I
> > have not found an example of doing this with an automapped table.  Is
> there
> > a easy way to do this?
>
> You can override specific columns on an automapped table by
> pre-declaring the class:
>
>   http://docs.sqlalchemy.org/en/latest/orm/extensions/automap.
> html#specifying-classes-explicitly
>
> I haven't tried it, but I would assume that you can use any of the
> normal facilities for modifying column behaviour at that point. For
> example, I think you could do something like this:
>
> class Hosts(automap):
>     __tablename__ = 'hosts'
>     _mac_address = Column('mac_address', BINARY)
>     @property
>     def mac_address(self):
>         return decode_mac_address(self._mac_address)
>
>     @mac_address.setter
>     def mac_address(self, value):
>         self._mac_address = encode_mac_address(value)
>
> If you want to be able to query using the decoded values, you could
> also try hybrid properties.
>
> Hope that helps,
>
> Simon
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "sqlalchemy" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/sqlalchemy/uxto-cNocFw/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> sqlalchemy+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> 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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to