2023-07-10 17:06:43 +08:00
|
|
|
from django.db import models
|
|
|
|
from django.contrib.gis.db import models as gis_models
|
2023-07-11 15:03:42 +08:00
|
|
|
from django.contrib.gis.geos import GEOSGeometry
|
|
|
|
from django.db.models.signals import post_migrate
|
|
|
|
from django.dispatch import receiver
|
2023-07-10 17:06:43 +08:00
|
|
|
# Create your models here.
|
|
|
|
|
|
|
|
|
|
|
|
class Landmark(models.Model):
|
|
|
|
name = models.CharField(max_length=64)
|
|
|
|
location = gis_models.PolygonField()
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
2023-07-11 15:03:42 +08:00
|
|
|
|
|
|
|
|
|
|
|
@receiver(post_migrate)
|
2023-07-11 15:06:09 +08:00
|
|
|
def populate_landmarks(sender, **kwargs):
|
2023-07-11 15:03:42 +08:00
|
|
|
if sender.name == 'landmarks':
|
|
|
|
SRID = 4326
|
|
|
|
Landmark.objects.get_or_create(
|
|
|
|
name='Gymnasium',
|
|
|
|
location=GEOSGeometry(
|
|
|
|
'POLYGON ((124.656383 8.485963, 124.656576 8.485483, 124.657009 8.485659, 124.656827 8.486126, 124.656383 8.485963))',
|
2023-07-11 15:05:38 +08:00
|
|
|
srid=SRID
|
2023-07-11 15:03:42 +08:00
|
|
|
)
|
|
|
|
)
|
|
|
|
Landmark.objects.get_or_create(
|
|
|
|
name='Arts & Culture Building',
|
|
|
|
location=GEOSGeometry(
|
|
|
|
'POLYGON ((124.658427 8.486268, 124.658432 8.48617, 124.658582 8.486202, 124.658555 8.4863, 124.658427 8.486268))',
|
2023-07-11 15:05:38 +08:00
|
|
|
srid=SRID
|
2023-07-11 15:03:42 +08:00
|
|
|
)
|
|
|
|
)
|
|
|
|
# Add more predefined records as needed
|