Foros del Web » Programando para Internet » Python »

[SOLUCIONADO] Django choice field list

Estas en el tema de Django choice field list en el foro de Python en Foros del Web. hola tengo este codigo @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código Python: Ver original def update_cart_batch ( request ) :     if request. method == 'POST' :   ...
  #1 (permalink)  
Antiguo 02/02/2014, 11:54
 
Fecha de Ingreso: diciembre-2011
Mensajes: 408
Antigüedad: 12 años, 3 meses
Puntos: 18
Django choice field list

hola tengo este codigo

Código Python:
Ver original
  1. def update_cart_batch(request):
  2.     if request.method == 'POST':
  3.         cart = Cart(request)
  4.         products = request.POST.getlist('product')
  5.         qtys = request.POST.getlist('qty')
  6.         if (len(products) > 0) and  (len(qtys) > 0):
  7.             for i in range(len(products)):
  8.                 product_id = int(products[i])
  9.                 qty =  int(qtys[i])
  10.                 try:
  11.                     product = CatalogProduct.objects.get(publish=True, id=product_id)
  12.                     if qty >= 1 and product.qty >= qty :
  13.                         updateCart(cart,product,qty)
  14.                     #add flash message if the product dont have stock
  15.                 except CatalogProduct.DoesNotExist:
  16.                     pass
  17.    
  18.     my_url = reverse("catalog_get_cart")
  19.     return HttpResponseRedirect(my_url)


y me gustaria traladarlo a un form y validarlo por alli los productos son una lista

Código Python:
Ver original
  1. <input name="product" type="hidden" value="{{ item.product.id }}">
  2. <input name="qty" type="number" value="{{ item.quantity }}">
  #2 (permalink)  
Antiguo 02/02/2014, 15:43
 
Fecha de Ingreso: diciembre-2011
Mensajes: 408
Antigüedad: 12 años, 3 meses
Puntos: 18
Respuesta: Django choice field list

estoy usando este tutorial

http://www.huyng.com/posts/django-cu...y-value-pairs/
  #3 (permalink)  
Antiguo 02/02/2014, 16:18
 
Fecha de Ingreso: diciembre-2011
Mensajes: 408
Antigüedad: 12 años, 3 meses
Puntos: 18
Respuesta: Django choice field list

tengo este widget
Código Python:
Ver original
  1. from django.utils.datastructures import MultiValueDict
  2. class Test(Widget):
  3.     input_type = 'hidden'
  4.     is_hidden = True
  5.     def __init__(self, attrs=None):
  6.         if attrs is not None:
  7.             self.input_type = attrs.pop('type', self.input_type)
  8.         super(Test, self).__init__(attrs)
  9.  
  10.     def value_from_datadict(self, data, files, name):
  11.        
  12.         return data.gelist(data,None)

pero cuando trato de acceder via cleanned data no anda porque retorna una lista pero no se que pasa me dice da error

KeyError test

Código Python:
Ver original
  1. test = self.cleaned_data['test']

Etiquetas: django, field, list
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 16:39.