json - Django REST Framework Batch PUT (Update) -
i have implemented viewsets , routers, making api returns me specific fields, info correctly, , can update (put) just one of details in json, 1 one, , need update of them @ same time.
i have in serializers.py
class ocompradetalleserializer(serializers.hyperlinkedmodelserializer): # producto = productoserializer(many=false) item = serializers.relatedfield(source='producto.modelo') descripcion = serializers.relatedfield(source='producto.descripcion') unidad = serializers.relatedfield(source='producto.unidad') # ocompra = ocompraserializer(many = false) class meta: model = ocompradetalle fields = ('url','item','descripcion','unidad','cantidad_ordenada','cantidad_recibida','fecha_entrega','precio','epc')
the api returns me this
http 200 ok content-type: application/json vary: take allow: get, post, head, options [ { "url": "http://localhost:8000/api/ocompradetalle/1/", "item": "aans/428375", "descripcion": "splicing kit shipping assembly", "unidad": "pza", "cantidad_ordenada": "1", "cantidad_recibida": "1", "fecha_entrega": "2015-07-14", "precio": "500", "epc": "0320caf425" }, { "url": "http://localhost:8000/api/ocompradetalle/5/", "item": "aans/53042", "descripcion": "nozzle f-1/2 w/blow off cap,lockwashers", "unidad": "pza", "cantidad_ordenada": "5", "cantidad_recibida": "0", "fecha_entrega": "2015-07-14", "precio": "300", "epc": "0436f0becd" }, ...
so allow section indicates cant put, if open single 1 detail, this:
http 200 ok content-type: application/json vary: take allow: get, put, patch, delete, head, options { "url": "http://localhost:8000/api/ocompradetalle/1/", "item": "aans/428375", "descripcion": "splicing kit shipping assembly", "unidad": "pza", "cantidad_ordenada": "1", "cantidad_recibida": "1", "fecha_entrega": "2015-07-14", "precio": "500", "epc": "0320caf425" }
making possible update, question is: how can set (update) whole json @ same time instead of making update every single entry?
note: the'item','descripcion','unidad'
fields comes model, thats why have productoserializer
commented, decided include specific values in json.
note 2: need set or update cantidad_recibida
value every entry.
django rest framework not allow batch modifications objects, bundle has been created brings batch updating. django rest framework bulk bundle allows add together mixin generic view (including viewsets) can give ability mass create, update, or delete objects.
it can made work routers slight modifications. should allow looking for.
note 2: need set or update cantidad_recibida value every entry.
this sounds looking patch
, though doesn't allow object creation in same way put
allows.
json django django-rest-framework
No comments:
Post a Comment