Ticket #5438: proxy_newmodel_none.patch

File proxy_newmodel_none.patch, 1.6 KB (added by rcoup, 7 years ago)
  • django/contrib/gis/db/models/proxy.py

     
    1919        # Getting the value of the field.
    2020        geom_value = obj.__dict__[self._field.attname]
    2121
    22         if (geom_value is None) or (isinstance(geom_value, GEOSGeometry)):
     22        if isinstance(geom_value, GEOSGeometry):
    2323            # If the value of the field is None, or is already a GEOS Geometry
    2424            #  no more work is needed.
    25             geom = geom_value
     25            geom = geom_value
     26        elif (geom_value is None) or (geom_value==''):
     27            geom = None
    2628        else:
    2729            # Otherwise, a GEOSGeometry object is built using the field's contents,
    2830            #  and the model's corresponding attribute is set.
  • django/contrib/gis/tests/geoapp/tests.py

     
    256256        self.assertEqual('Texas', Country.objects.get(mpoly__relate=(pnt2, 'T********')).name)
    257257        self.assertEqual('Lawrence', City.objects.get(point__relate=(ks.poly, 'T********')).name)
    258258
     259    def test16_createnull(self):
     260        "Testing creating a model instance and the geometry being None"
     261        c = City()
     262        self.assertEqual(c.point, None)
     263
    259264def suite():
    260265    s = unittest.TestSuite()
    261266    s.addTest(unittest.makeSuite(GeoModelTest))
Back to Top