In [1]:
!head circuitos.csv
In [2]:
!head secciones.csv
In [3]:
!head mesas.csv
In [3]:
from csv import DictReader
Seccion.objects.all().delete()
Out[3]:
In [4]:
for seccion in DictReader(open('secciones.csv')):
Seccion.objects.create(**seccion)
In [6]:
secciones = {s.numero: s for s in Seccion.objects.all()}
circuitos = []
for circuito in DictReader(open('circuitos.csv')):
circuito['seccion'] = secciones[int(circuito['seccion'])]
circuitos.append(Circuito(**circuito))
Circuito.objects.bulk_create(circuitos);
In [8]:
e = Eleccion.objects.get(id=1)
In [11]:
circuitos = {c.numero: c for c in Circuito.objects.all()}
mesas = []
for mesa in DictReader(open('mesas.csv')):
mesa['circuito'] = circuitos[mesa['circuito']]
mesa.pop('fake_id')
mesa.pop('url')
mesas.append(Mesa(eleccion=e, **mesa))
Mesa.objects.bulk_create(mesas);
In [ ]: