You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
964 B

from django.core.management.base import BaseCommand
from service.models import Point
from django.contrib.gis.geos import Point as GeoPoint
from pandas import read_excel
from tqdm import tqdm
def import_points(file_path):
Point.objects.all().delete()
point_models = []
df = read_excel(file_path)
df = df.fillna(0)
df_rows = list(df.iterrows())
for id_, i in tqdm(df_rows):
data = i.to_dict()
lat, lng = data.pop('lat'),data.pop('lng')
geometry = GeoPoint(lng, lat, srid=4326)
try:
point_models.append(Point(point=geometry, **data))
except Exception as e:
print(e)
pass
Point.objects.bulk_create(point_models, batch_size=10000)
class Command(BaseCommand):
requires_system_checks = False
def add_arguments(self, parser):
parser.add_argument('-f', '--file', type=str)
def handle(self, file, *args, **options):
import_points(file)