9
9
10
10
11
11
class SpatialProxy (DeferredAttribute ):
12
- def __init__ (self , klass , field ):
12
+ def __init__ (self , klass , field , load_func = None ):
13
13
"""
14
14
Initialize on the given Geometry or Raster class (not an instance)
15
15
and the corresponding field.
16
16
"""
17
17
self ._field = field
18
18
self ._klass = klass
19
+ self ._load_func = load_func or klass
19
20
super ().__init__ (field .attname , klass )
20
21
21
22
def __get__ (self , instance , cls = None ):
@@ -42,7 +43,7 @@ def __get__(self, instance, cls=None):
42
43
else :
43
44
# Otherwise, a geometry or raster object is built using the field's
44
45
# contents, and the model's corresponding attribute is set.
45
- geo_obj = self ._klass (geo_value )
46
+ geo_obj = self ._load_func (geo_value )
46
47
setattr (instance , self ._field .attname , geo_obj )
47
48
return geo_obj
48
49
@@ -61,7 +62,7 @@ def __set__(self, instance, value):
61
62
# For raster fields, assure input is None or a string, dict, or
62
63
# raster instance.
63
64
pass
64
- elif isinstance (value , self ._klass ) and ( str ( value . geom_type ). upper () == gtype or gtype == 'GEOMETRY' ) :
65
+ elif isinstance (value , self ._klass ):
65
66
# The geometry type must match that of the field -- unless the
66
67
# general GeometryField is used.
67
68
if value .srid is None :
0 commit comments