Commit 0996c5d4 authored by cermak's avatar cermak
Browse files

Cherry pick from develop - add ids to rest api

parent a7650bf9
...@@ -19,18 +19,21 @@ class ProposalSerializer(serializers.ModelSerializer): ...@@ -19,18 +19,21 @@ class ProposalSerializer(serializers.ModelSerializer):
fields = ('proposal', 'title', 'users', 'localcontacts') fields = ('proposal', 'title', 'users', 'localcontacts')
def get_users(self, obj): def get_users(self, obj):
userlist = [{ 'name': obj.proposer.contact.name, userlist = [{ 'id': obj.proposer.contact.pk,
'name': obj.proposer.contact.name,
'email': obj.proposer.contact.email, 'email': obj.proposer.contact.email,
'affiliation': str(obj.proposer.contact.affiliation), 'affiliation': str(obj.proposer.contact.affiliation),
}] }]
for u in obj.coproposers.all(): for u in obj.coproposers.all():
userlist.append({ userlist.append({
'id': u.pk,
'name': u.name, 'name': u.name,
'email': u.email, 'email': u.email,
'affiliation': str(u.affiliation), 'affiliation': str(u.affiliation),
}) })
if obj.supervisor: if obj.supervisor:
userlist.append({ userlist.append({
'id': obj.supervisor.pk,
'name': obj.supervisor.name, 'name': obj.supervisor.name,
'email': obj.supervisor.email, 'email': obj.supervisor.email,
'affiliation': str(obj.supervisor.affiliation), 'affiliation': str(obj.supervisor.affiliation),
...@@ -41,6 +44,7 @@ class ProposalSerializer(serializers.ModelSerializer): ...@@ -41,6 +44,7 @@ class ProposalSerializer(serializers.ModelSerializer):
lclist = [] lclist = []
for u in obj.local_contacts.all(): for u in obj.local_contacts.all():
lclist.append({ lclist.append({
'id': u.pk,
'name': u.name, 'name': u.name,
'email': u.email, 'email': u.email,
'affiliation': str(u.affiliation), 'affiliation': str(u.affiliation),
...@@ -49,7 +53,7 @@ class ProposalSerializer(serializers.ModelSerializer): ...@@ -49,7 +53,7 @@ class ProposalSerializer(serializers.ModelSerializer):
# API views: # API views:
class MyProposalList(generics.ListCreateAPIView): class MyProposalList(generics.ListAPIView):
permission_classes = [permissions.IsAuthenticated] permission_classes = [permissions.IsAuthenticated]
def get(self, request): def get(self, request):
...@@ -60,5 +64,4 @@ class MyProposalList(generics.ListCreateAPIView): ...@@ -60,5 +64,4 @@ class MyProposalList(generics.ListCreateAPIView):
serializer = ProposalSerializer(proposals, many=True) serializer = ProposalSerializer(proposals, many=True)
return Response(serializer.data) return Response(serializer.data)
#queryset = User.objects.all() queryset = Proposals.objects.all()
#serializer_class = UserSerializer
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment