From 50dfbc7e793f1bcfdd22f9cffcefde31f14b186b Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 2 Jan 2009 18:22:50 +0000 Subject: - Custom comparator classes used in conjunction with column_property(), relation() etc. can define new comparison methods on the Comparator, which will become available via __getattr__() on the InstrumentedAttribute. In the case of synonym() or comparable_property(), attributes are resolved first on the user-defined descriptor, then on the user-defined comparator. --- examples/postgis/postgis.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'examples') diff --git a/examples/postgis/postgis.py b/examples/postgis/postgis.py index 841bce31c..c463cca26 100644 --- a/examples/postgis/postgis.py +++ b/examples/postgis/postgis.py @@ -123,21 +123,14 @@ class GisComparator(ColumnProperty.ColumnComparator): """Intercepts standard Column operators on mapped class attributes and overrides their behavior. - The PropComparator API currently does not allow "custom" - operators to be added, so only those operators which - already exist on Column can be overridden here. Additional - GIS-specific operators can be implemented as standalone - functions. """ def __eq__(self, other): return self.__clause_element__().op('~=')(_to_postgis(other)) -def intersects(x, y): - """An example standalone GIS-specific comparison operator.""" - - return _to_postgis(x).op('&&')(_to_postgis(y)) + def intersects(self, other): + return self.__clause_element__().op('&&')(_to_postgis(other)) class gis_element(object): """Represents a geometry value. @@ -219,7 +212,7 @@ if __name__ == '__main__': assert r1 is r2 is r3 # illustrate the "intersects" operator - print session.query(Road).filter(intersects(Road.road_geom, r1.road_geom)).all() + print session.query(Road).filter(Road.road_geom.intersects(r1.road_geom)).all() # illustrate usage of the "wkt" accessor. this requires a DB # execution to call the AsText() function so we keep this explicit. -- cgit v1.2.1