Hi Julien,
Do not monkey patch so quickly ! ;)
Adding fields with Piston is really easy : just add it's name in one of the handler fields list.
fields = ("my_model_field", "my_extra_field")
"my_extra_field" can refer to :
- a local classmethod
- a handler's model related model
- a handler's model method
- a handler's model fields
So you can put what ever you want as field name in the list.
And if your extra_field is not a method or field of your original model, just add a local classmethod to do the job.
And of course use inheritence between handlers if you have the same needs for few handlers.
Anyway, if you just add "__unicode__" in the fields list, I should work as is, as __unicode__ is of course a method of your original model.
Never tried it, but I can't see a reason for this not to work.
Regarding the fields lists, in the piston native repo, you have two lists : fields and list_fields
The first list is used by the handler when serializing an instance, the second when serializing a list of instances (a queryset).
If you want to have different fields for a model when considered as a related model, you can have a look at our fork :
https://bitbucket.org/liberation/django-piston/
We have added the related_fields possibility. And other few little things. For this, we hope the community fork will concretize soon ! :)
Yohan
PS : Are we speaking english here ? Really ? ;)