Last active
August 29, 2015 13:55
-
-
Save meoooh/8749144 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from django.db import models | |
class Question(models.Model): | |
contents = models.TextField() | |
class Answer(models.Model): | |
contents = models.TextField() | |
question = models.ForeignKey(Question) |
This file contains hidden or 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
from rest_framework import serializers | |
from .models import * | |
class QuestionSerializer(serializers.ModelSerializer): | |
class Meta: | |
model = Question | |
class AnswerSerializer(serializers.ModelSerializer): | |
question = QuestionSerializer() | |
class Meta: | |
model = Answer |
This file contains hidden or 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
from django.conf.urls import patterns, url, include | |
from rest_framework import routers | |
from app import views | |
router = routers.SimpleRouter(trailing_slash=False) | |
router.register(r'answers', views.AnswerViewSet) | |
router.register(r'questions', views.QuestionViewSet) | |
urlpatterns = patterns('vom', | |
url(r'^', include(router.urls)), | |
) |
This file contains hidden or 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
from app import models, serializers | |
from rest_framework import viewsets | |
class QuestionViewSet(viewsets.ModelViewSet): | |
serializer_class = serializers.QuestionSerializer | |
queryset = models.Question.objects.all() | |
class AnswerViewSet(viewsets.ModelViewSet): | |
serializer_class = serializers.AnswerSerializer | |
queryset = models.Answer.objects.all() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment