I am using a plunger and I would like to pop out a custom format for my answer.
My model looks something like this:
class Car(db.Model): name = models.CharField(max_length=256) color = models.CharField(max_length=256)
Now when I issue a GET request for something like / api / cars / 1 /, I want to get this answer:
{'name' : 'BMW', 'color' : 'Blue', 'link' : {'self' : '/api/cars/1'} }
However, the piston only displays this:
{'name' : 'BMW', 'color' : 'Blue'}
In other words, I want to customize the presentation of a specific resource.
My piston resource handler now looks like this:
class CarHandler(AnonymousBaseHandler): allowed_methods = ('GET',) model = Car fields = ('name', 'color',) def read(self, request, car_id): return Car.get(pk=car_id)
Therefore, I do not understand where I have the opportunity to configure the data. If I donβt have to rewrite the JSON emitter, but it is like stretching.
python rest django django-piston
drozzy
source share