este es el codigo de como lo guardo:
Código Python:
Ver originalclass DataExcelProcessView(TemplateView):
template_name = 'app/dataexcel_process.html'
def get(self, request, *args, **kwargs):
return super(DataExcelProcessView, self).get(request, args, kwargs)
def get_context_data(self, **kwargs):
ctx = super(DataExcelProcessView, self).get_context_data(**kwargs)
ctx['process'] = self.process_file()
return ctx
def process_file(self):
object = get_object_or_404(DataExcel, pk=self.kwargs['pk'])
book = xlrd.open_workbook(object.file.path)
hoja1 = book.sheet_by_index(0)
fields = ('CodSucursal', 'Sucursal', 'CodDivision')
products = [Product(Id_DataExcel=DataExcel.objects.get(pk=object.id),**{fields[i]: cell for i, cell in enumerate(hoja1.row_values(rowid))}) # recorrido para guardar la data
for rowid in range(1, hoja1.nrows)]
try:
Product.objects.bulk_create(products)
except IntegrityError as e:
return False