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
Source:stackexchange.com