diff options
author | Stephen Finucane <stephen@that.guru> | 2016-10-28 18:29:49 +0100 |
---|---|---|
committer | Stephen Finucane <stephen@that.guru> | 2016-12-23 23:37:55 +0000 |
commit | 9edc08a648f67067da80a5a71f7a3a1c3064e5d4 (patch) | |
tree | 23cfb22a1cd2779338abc4e39baa5b416dc829f6 | |
parent | 207bc10f74034509f0c17fad1dfc8713e73a5a3e (diff) | |
download | patchwork-9edc08a648f67067da80a5a71f7a3a1c3064e5d4.tar patchwork-9edc08a648f67067da80a5a71f7a3a1c3064e5d4.tar.gz |
REST: Make use of the 'source' property
This is apparently the correct way to rename fields, and will ensure a
future API version that supports writes will work correctly.
Signed-off-by: Stephen Finucane <stephen@that.guru>
Reviewed-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Andy Doan <andy.doan@linaro.org>
-rw-r--r-- | patchwork/api/project.py | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/patchwork/api/project.py b/patchwork/api/project.py index 2f63694..af2aea0 100644 --- a/patchwork/api/project.py +++ b/patchwork/api/project.py @@ -17,6 +17,7 @@ # along with Patchwork; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +from rest_framework.serializers import CharField from rest_framework.serializers import HyperlinkedModelSerializer from patchwork.api.base import PatchworkPermission @@ -25,17 +26,14 @@ from patchwork.models import Project class ProjectSerializer(HyperlinkedModelSerializer): - def to_representation(self, instance): - data = super(ProjectSerializer, self).to_representation(instance) - data['link_name'] = data.pop('linkname') - data['list_email'] = data.pop('listemail') - data['list_id'] = data.pop('listid') - return data + link_name = CharField(max_length=255, source='linkname') + list_id = CharField(max_length=255, source='listid') + list_email = CharField(max_length=200, source='listemail') class Meta: model = Project - fields = ('url', 'name', 'linkname', 'listid', 'listemail', 'web_url', - 'scm_url', 'webscm_url') + fields = ('url', 'name', 'link_name', 'list_id', 'list_email', + 'web_url', 'scm_url', 'webscm_url') class ProjectViewSet(PatchworkViewSet): |