Hello!
I'm using pydal to work with a mongoDB database, im using this structure:
db.define_table('tarifas',
Field('fk_hotel_id',
'integer',
required=True,
notnull=True,
requires=IS_INT_IN_RANGE(0)),
Field('fk_habitacion_id',
'integer',
required=True,
default=None,
requires=IS_INT_IN_RANGE(0)),
Field('tarifa_min',
'decimal(11, 2)',
required=True,
default=None,
requires=IS_DECIMAL_IN_RANGE(-1e100, 1e100)),
Field('tarifa_max',
'decimal(11, 2)',
required=True,
default=None,
requires=IS_DECIMAL_IN_RANGE(-1e100, 1e100)),
Field('modificador_semana',
'decimal(2, 2)',
length=2,
requires=IS_EMPTY_OR(IS_DECIMAL_IN_RANGE(0,
99))),
Field('modificador_eventos',
'list:string'))
The modificador_eventos field will be a json with a list format, so im
trying to insert a list in it using this code:
eventos = json.loads(eventos)
lista = [eventos, eventos, eventos]
respuesta = db(db.tarifas.id ==
id).validate_and_update(modificador_eventos=lista).as_dict()
Where var eventos is:
{
"nombre": "qq",
"fecha_inicio": "12/12/2012",
"fecha_fin": "14/12/2012",
"existencias": "3",
"descuento": "21"
}
When i try to do that i receive this exception:
File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/sync.py",
line 130, in handle
self.handle_request(listener, req, client, addr)
File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/sync.py",
line 171, in handle_request
respiter = self.wsgi(environ, resp.start_response)
File "/usr/local/lib/python2.7/dist-packages/falcon/api.py", line 182, in
__call__
responder(req, resp, **params)
File "/usr/share/nginx/html/falcon/tarifas/controlador/api.py", line 158,
in on_post
resultado = self.tarifas.insertarEvento(req)
File "../modelos/tarifas.py", line 52, in insertarEvento
respuesta = db(db.tarifas.id ==
id).validate_and_update(modificador_eventos=lista).as_dict()
File "/usr/local/lib/python2.7/dist-packages/pydal/objects.py", line
2116, in validate_and_update
ret = self.db._adapter.update(tablename, self.query, fields)
File "/usr/local/lib/python2.7/dist-packages/pydal/adapters/mongo.py",
line 447, in update
expanded = Expansion(self, 'update', query, fields)
File "/usr/local/lib/python2.7/dist-packages/pydal/adapters/mongo.py",
line 635, in __init__
self._expand_fields(self._fields_loop_abort)
File "/usr/local/lib/python2.7/dist-packages/pydal/adapters/mongo.py",
line 751, in _expand_fields
self._expand_field(field, value, mid_loop)
File "/usr/local/lib/python2.7/dist-packages/pydal/adapters/mongo.py",
line 762, in _expand_field
expanded = self.adapter.expand(value, field.type)
File "/usr/local/lib/python2.7/dist-packages/pydal/adapters/mongo.py",
line 187, in _expand
raise NotImplementedError("How did you reach this line of code???")
NotImplementedError: How did you reach this line of code???
However if i insert just the dict (i mean, the var eventos without
convertir it to list) everythings works fine. I also tried this:
db(db.tarifas.id ==
id).validate_and_update(modificador_eventos=json.dumps(lista).as_dict()
And i dont recieve any exception, but it insert in a weird format, looks
like this:
[{\"nombre\": \"qq\", \"fecha_inicio\": \"12/12/2012\", \"fecha_fin\":
\"14/12/2012\", \"descuento\": \"21\", \"existencias\": \"3\"},
{\"nombre\": \"qq\", \"fecha_inicio\": \"12/12/2012\", \"fecha_fin\":
\"14/12/2012\", \"descuento\": \"21\", \"existencias\": \"3\"},
{\"nombre\": \"qq\", \"fecha_inicio\": \"12/12/2012\", \"fecha_fin\":
\"14/12/2012\", \"descuento\": \"21\", \"existencias\": \"3\"}]
Im pretty sure this happens beacause the mongo plugin converts it to json
again. So, you have any suggestion in this matter or some workaround for
what i want to do?
Thanks very much for any help you can provide
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.