Open dheerajchand opened 1 week ago
markdown went a little crazy there.
Here is the management command, quoted, and linked.
I have moved it out of the management directory for now because it is not working and I don't want it in with things that are working, but on my local filesystem I have kept it in the proper location.
from django.core.management.base import BaseCommand
from locations.models import *
from utilities import *
from django.conf import settings
# logging
import logging
logger = logging.getLogger("django")
class Command(BaseCommand):
def handle(self, *args, **kwargs):
# Since the CSV headers match the model fields,
# you only need to provide the file's path (or a Python file object)
timezones_csv = settings.TABULAR_DATA_SUBDIRECTORY / "tz.csv"
column_to_field_mapping = {"tzid": "tzid", "geom": "geometry"}
Timezone.objects.all().delete()
insert_count = Timezone.objects.from_csv(
timezones_csv,
mapping=column_to_field_mapping,
)
message = ""
message += f"{insert_count} records inserted"
logger.info(message)
I've tried to capture a stacktrace, but the error seems to take down my terminal. I've exported the contents of a shapefile to CSV using
GeoPandas
:And I try to import on this model:
But I get an error that crashes the terminal. Is this plugin able to work with geometry columns for GeoDjango? Do I need to do something different? The CSV is too big to attach, but you can see the file I am converting from here:
https://github.com/evansiroky/timezone-boundary-builder/releases/download/2024a/timezones-with-oceans-now.shapefile.zip
Thanks!