Skip to content

Instantly share code, notes, and snippets.

@coldmind
Created December 31, 2014 18:06
Show Gist options
  • Save coldmind/be61c330c7e56974bb51 to your computer and use it in GitHub Desktop.
Save coldmind/be61c330c7e56974bb51 to your computer and use it in GitHub Desktop.
An idea about spatialite dynamic fields
Index: django/django/contrib/gis/db/backends/spatialite/models.py
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- django/django/contrib/gis/db/backends/spatialite/models.py (revision 51890ce8898f821d28f2f6fb6071c936e9bd88f0)
+++ django/django/contrib/gis/db/backends/spatialite/models.py (revision )
@@ -2,6 +2,7 @@
The GeometryColumns and SpatialRefSys models for the SpatiaLite backend.
"""
from django.db import connection, models
+from django.db.backends.signals import connection_created
from django.contrib.gis.db.backends.base import SpatialRefSysMixin
from django.utils.encoding import python_2_unicode_compatible
@@ -13,10 +14,6 @@
"""
f_table_name = models.CharField(max_length=256)
f_geometry_column = models.CharField(max_length=256)
- if connection.ops.spatial_version[0] >= 4:
- type = models.IntegerField(db_column='geometry_type')
- else:
- type = models.CharField(max_length=30)
coord_dimension = models.IntegerField()
srid = models.IntegerField(primary_key=True)
spatial_index_enabled = models.IntegerField()
@@ -57,8 +54,6 @@
auth_srid = models.IntegerField()
ref_sys_name = models.CharField(max_length=256)
proj4text = models.CharField(max_length=2048)
- if connection.ops.spatial_version[0] >= 4:
- srtext = models.CharField(max_length=2048)
@property
def wkt(self):
@@ -71,3 +66,14 @@
app_label = 'gis'
db_table = 'spatial_ref_sys'
managed = False
+
+
+def add_spatial_related_fields(sender, **kwargs):
+ spatial_version = connection.ops.spatial_version[0]
+ if spatial_version >= 4:
+ SpatialiteSpatialRefSys.add_to_class('srtext', models.CharField(max_length=2048))
+ SpatialiteGeometryColumns.add_to_class('type', models.IntegerField(db_column='geometry_type'))
+ else:
+ SpatialiteGeometryColumns.add_to_class('type', models.CharField(max_length=30))
+
+connection_created.connect(add_spatial_related_fields)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment