Ver Mensaje Individual
  #3 (permalink)  
Antiguo 14/08/2014, 12:24
andy2507
 
Fecha de Ingreso: julio-2011
Ubicación: Peru
Mensajes: 92
Antigüedad: 12 años, 9 meses
Puntos: 1
Respuesta: Campo Chardfield aunmenta .0 sin ser campo decimal

este es el codigo de como lo guardo:

Código Python:
Ver original
  1. class DataExcelProcessView(TemplateView):
  2.     template_name = 'app/dataexcel_process.html'
  3.  
  4.     def get(self, request, *args, **kwargs):
  5.         return super(DataExcelProcessView, self).get(request, args, kwargs)
  6.  
  7.     def get_context_data(self, **kwargs):
  8.         ctx = super(DataExcelProcessView, self).get_context_data(**kwargs)
  9.         ctx['process'] = self.process_file()
  10.         return ctx
  11.  
  12.     def process_file(self):
  13.         object = get_object_or_404(DataExcel, pk=self.kwargs['pk'])
  14.         book = xlrd.open_workbook(object.file.path)
  15.         hoja1 = book.sheet_by_index(0)
  16.         fields = ('CodSucursal', 'Sucursal', 'CodDivision')
  17.  
  18.         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
  19.                     for rowid in range(1, hoja1.nrows)]
  20.  
  21.         try:
  22.             Product.objects.bulk_create(products)
  23.  
  24.         except IntegrityError as e:
  25.             return False