[Django]-Django REST: What's the recommended approach for supporting nested collections in URLs, such as /users/5/snippets/

8👍

url(r'^/sessions/(?P<session_pk>\d+)/speakers/$', views.SpeakerBySessionList.as_view()),

class SpeakerBySessionList(generics.ListCreateAPIView):
    model = Speaker
    serializer_class = serializers.SpeakerSerializer

    def get_queryset(self):
        session_pk = self.kwargs.get('session_pk', None)
        if session_pk is not None:
            return Speaker.objects.filter(session__pk=session_pk)
        return []

class Session(models.Model):
    name = models.CharField(max_length=150)

class Speaker(models.Model):
    name = models.CharField(max_length=100)
    session = models.ForeignKey(Session, related_name='speakers')

If you want to see a more complex django / ember example be sure to checkout my github project

https://github.com/toranb/complex-ember-data-example

Leave a comment