Last active
August 29, 2015 14:21
-
-
Save court-jus/d787537c9581193cf02e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HTTP 200 OK | |
Content-Type: application/json | |
Vary: Accept | |
Allow: GET, POST, HEAD, OPTIONS | |
[ | |
{ | |
"id": 87, | |
"nom": "Panel 200", | |
"analyseur": { | |
"id": 200, | |
"automate": "13644", | |
"nom": "Analyseur 1" | |
} | |
}, | |
....... | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# sent to /qc/api/panels/ via the RESTframework html interface | |
{ | |
"nom": "test", | |
"analyseur": { | |
"id": 104, | |
"automate": "Advia 1800", | |
"nom": "Advia 1800" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HTTP 400 BAD REQUEST | |
Content-Type: application/json | |
Vary: Accept | |
Allow: GET, POST, HEAD, OPTIONS | |
{ | |
"analyseur": { | |
"nom": [ | |
"This field must be unique." | |
], | |
"automate": [ | |
"This field must be unique." | |
] | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from rest_framework import serializers, viewsets, routers | |
from qc.models import Panel | |
from automate.models import Analyseur | |
class AnalyseurSerializer(serializers.ModelSerializer): | |
class Meta: | |
model = Analyseur | |
fields = ("id", "automate", "nom") | |
class PanelSerializer(serializers.ModelSerializer): | |
analyseur = AnalyseurSerializer() | |
class Meta: | |
model = Panel | |
fields = ("id", "nom", "analyseur") | |
class PanelViewSet(viewsets.ModelViewSet): | |
queryset = Panel.objects.select_related() | |
serializer_class = PanelSerializer | |
router = routers.DefaultRouter() | |
router.register(r'panels', PanelViewSet) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment