Skip to content

Commit

Permalink
Remove old geometry field on boundary
Browse files Browse the repository at this point in the history
  • Loading branch information
norkans7 committed Jan 10, 2025
1 parent 7563744 commit a4ce394
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 5.1.4 on 2025-01-10 15:04

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("locations", "0034_populate_json_geometry"),
]

operations = [
migrations.RemoveField(
model_name="adminboundary",
name="simplified_geometry",
),
]
18 changes: 1 addition & 17 deletions temba/locations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,11 @@
from mptt.models import MPTTModel, TreeForeignKey
from smartmin.models import SmartModel

from django.contrib.gis.db import models
from django.db import models
from django.db.models import F, Value
from django.db.models.functions import Concat, Upper


# default manager for AdminBoundary, doesn't load geometries
class NoGeometryManager(models.Manager):
def get_queryset(self):
return super().get_queryset().defer("simplified_geometry")


# optional 'geometries' manager for AdminBoundary, loads everything
class GeometryManager(models.Manager):
def get_queryset(self):
return super().get_queryset()


class AdminBoundary(MPTTModel, models.Model):
"""
Represents a single administrative boundary (like a country, state or district)
Expand All @@ -41,12 +29,8 @@ class AdminBoundary(MPTTModel, models.Model):
level = models.IntegerField()
parent = TreeForeignKey("self", null=True, on_delete=models.PROTECT, related_name="children", db_index=True)
path = models.CharField(max_length=768) # e.g. Rwanda > Kigali
simplified_geometry = models.MultiPolygonField(null=True)
geometry = models.JSONField(null=True)

objects = NoGeometryManager()
geometries = GeometryManager()

@staticmethod
def get_geojson_dump(name, features):
# build a feature collection
Expand Down
1 change: 0 additions & 1 deletion temba/locations/tests/test_geojson.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,6 @@ def test_import_geojson(self):
self.assertEqual(0, AdminBoundary.objects.filter(level=3).count())

self.country = AdminBoundary.objects.get(level=0)
self.assertIsNone(self.country.simplified_geometry)
self.assertEqual(self.country.geometry, matchers.Dict())

def assertOSMIDs(self, ids):
Expand Down
4 changes: 2 additions & 2 deletions temba/locations/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def derive_url_pattern(cls, path, action):
return r"^%s/%s/(?P<osmId>\w+\.?\d+\.?\d?\_?\d?)/$" % (path, action)

def get_object(self):
return AdminBoundary.geometries.get(osm_id=self.kwargs["osmId"])
return AdminBoundary.objects.get(osm_id=self.kwargs["osmId"])

def render_to_response(self, context):
if self.object.children.all().count() > 0:
Expand All @@ -68,7 +68,7 @@ def derive_url_pattern(cls, path, action):
return r"^%s/%s/(?P<osmId>[\w\.]+)/$" % (path, action)

def get_object(self):
return AdminBoundary.geometries.get(osm_id=self.kwargs["osmId"])
return AdminBoundary.objects.get(osm_id=self.kwargs["osmId"])

def post(self, request, *args, **kwargs):
# try to parse our body
Expand Down

0 comments on commit a4ce394

Please sign in to comment.