Re: [sqlalchemy] making a relationship on a column operation

2017-08-22 Thread Jonathan Vanasco
and thank you x 100

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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.


Re: [sqlalchemy] making a relationship on a column operation

2017-08-22 Thread Jonathan Vanasco


On Tuesday, August 22, 2017 at 2:16:42 PM UTC-4, Mike Bayer wrote:
 

> you're looking for: 
>
>
> http://docs.sqlalchemy.org/en/latest/orm/join_conditions.html#using-custom-operators-in-join-conditions
>  
>
>
I swear I searched first and spent an hour trying to figure this out.  And 
then there was literally the exact documentation I needed.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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.


Re: [sqlalchemy] making a relationship on a column operation

2017-08-22 Thread Mike Bayer
On Tue, Aug 22, 2017 at 12:19 PM, Jonathan Vanasco
 wrote:
> I can't seem to figure out how to transition a query for the Ip
> Blocks/ranges than a given IP address exists in, from a generic query into a
> relationship.  i keep getting foreign key errors, not matter what arguments
> I try.  The simplest form of what I'm trying to do is below:

you're looking for:

http://docs.sqlalchemy.org/en/latest/orm/join_conditions.html#using-custom-operators-in-join-conditions

>
>
>
> # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> - -
> # Standard imports
>
> import sqlalchemy
> from sqlalchemy.ext.declarative import declarative_base
> from sqlalchemy.orm import relationship
> from sqlalchemy.orm import sessionmaker
> from sqlalchemy import Integer, Column, ForeignKey, Unicode
> from sqlalchemy import create_engine
> import sqlalchemy.dialects.postgresql
>
> # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> - -
> # You probably don't need to overwrite this
> Base = declarative_base()
>
> # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> - -
> # Define some models that inherit from Base
>
> class IpAddress(Base):
> __tablename__ = 'ip_address'
> id = Column(Integer, primary_key=True)
> ip_address = Column(Unicode(16), nullable=False)
> ip_address__cidr = Column(sqlalchemy.dialects.postgresql.CIDR,
> nullable=False)
>
> class IpRange(Base):
> __tablename__ = 'ip_range'
> id = Column(Integer, primary_key=True)
> ip_range__cidr = Column(sqlalchemy.dialects.postgresql.CIDR,
> nullable=False)
>
> IpAddress.in_ip_ranges = relationship(
> IpRange,
>
> primaryjoin=IpAddress.ip_address__cidr.op('<<=')(IpRange.ip_range__cidr),
> viewonly=True,
> )
>
> # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> - -
> # set the engine
>
> engine =
> create_engine('postgresql://sa_test:sa_test@localhost/sqlalchemy_test',
> echo=True)
> Base.metadata.create_all(engine)
>
> # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> - -
> # do a simple query to trigger the mapper error
>
> sessionFactory = sessionmaker(bind=engine)
> s = sessionFactory()
>
> s.query(IpAddress).get(1)
>
>
>
>
> --
> SQLAlchemy -
> The Python SQL Toolkit and Object Relational Mapper
>
> http://www.sqlalchemy.org/
>
> To post example code, please provide an MCVE: Minimal, Complete, and
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full
> description.
> ---
> 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.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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.