Exemplo n.º 1
0
 def import_sites(modeladmin, request, queryset):
     with open('D:/Users/mcpherro/PycharmProjects/Sites/sites.csv', 'rb') as f:
         reader = csv.reader(f)
         for row in reader:
             country_name = row[2]
             for c in countries:
                 if row[2]==c[1]:
                     country_name = c[0]
             s = Site(id=row[0], site=row[1], country=country_name, data_source=row[3], site_type=row[7],
                      display=row[8])
             if row[4] != 'NA':
                 s.latitude = row[4]
             if row[5] != 'NA':
                 s.longitude = row[5]
             if row[6] != 'NA':
                 s.altitude = row[6]
             if row[4] != 'NA' and row[5] != 'NA':
                 pnt = django.contrib.gis.geos.GEOSGeometry('POINT(%s %s)' % (row[5], row[4]))
                 s.map_location = pnt
             s.save()
     return None         # Return None to display the change list page again.
Exemplo n.º 2
0
 def import_sites(modeladmin, request, queryset):
     with open('D:/Users/mcpherro/PycharmProjects/Sites/sites.csv', 'rb') as f:
         reader = csv.reader(f)
         for row in reader:
             country_name = row[2]
             for c in countries:
                 if row[2]==c[1]:
                     country_name = c[0]
             s = Site(id=row[0], site=row[1], country=country_name, data_source=row[3], site_type=row[7], 
                      display=row[8])
             if row[4] != 'NA':
                 s.latitude = row[4]
             if row[5] != 'NA':
                 s.longitude = row[5]
             if row[6] != 'NA':
                 s.altitude = row[6]
             if row[4] != 'NA' and row[5] != 'NA':
                 pnt = django.contrib.gis.geos.GEOSGeometry('POINT(%s %s)' % (row[5], row[4]))
                 s.map_location = pnt
             s.save()
     return None         # Return None to display the change list page again.