Skip to content

Commit

Permalink
Add gis deconstruct() method (this does not make schema work)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgodwin committed Nov 27, 2013
1 parent 96dd48c commit 4fcfc31
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions django/contrib/gis/db/models/fields.py
Expand Up @@ -105,6 +105,19 @@ def __init__(self, verbose_name=None, srid=4326, spatial_index=True, dim=2,


super(GeometryField, self).__init__(**kwargs) super(GeometryField, self).__init__(**kwargs)


def deconstruct(self):
name, path, args, kwargs = super(GeometryField, self).deconstruct()
# Always include SRID for less fragility; include others if they're
# not the default values.
kwargs['srid'] = self.srid
if self.dim != 2:
kwargs['dim'] = self.dim
if self.spatial_index != True:
kwargs['spatial_index'] = self.spatial_index
if self.geography != False:
kwargs['geography'] = self.geography
return name, path, args, kwargs

# The following functions are used to get the units, their name, and # The following functions are used to get the units, their name, and
# the spheroid corresponding to the SRID of the GeometryField. # the spheroid corresponding to the SRID of the GeometryField.
def _get_srid_info(self, connection): def _get_srid_info(self, connection):
Expand Down
2 changes: 1 addition & 1 deletion django/db/backends/schema.py
Expand Up @@ -110,7 +110,7 @@ def column_sql(self, model, field, include_default=False):
params = [] params = []
# Check for fields that aren't actually columns (e.g. M2M) # Check for fields that aren't actually columns (e.g. M2M)
if sql is None: if sql is None:
return None return None, None
# Work out nullability # Work out nullability
null = field.null null = field.null
# If we were told to include a default value, do so # If we were told to include a default value, do so
Expand Down

0 comments on commit 4fcfc31

Please sign in to comment.