I have a tv channel model and created a django-restframework viewlet which gives me a list and a detail view out of the box. On top I added two custom single-object views called all_events and now_and_next_event, as described here: Marking extra methods for routing. That works great so far.
class ChannelViewSet(viewsets.ModelViewSet):
"""
A viewset for viewing and editing channel instances.
"""
serializer_class = serializers.ChannelSerializer
queryset = Channel.objects.all()
@link()
def now_and_next_event(self, request, pk):
''' Show current and next event of single channel. '''
...
Now I would like to add a custom view which is NOT a single-object view but a list-like view:
class CurrentEvents(generics.ListCreateAPIView):
''' Show current event of all channels. '''
model = Event
serializer_class = serializers.EventSerializer
def get(self, request):
...
When I disable my viewlet and add a manual url pattern for it, it works as well. But I haven't figured out how to make them both work with the same 'api/channel/' prefix, or what I would like more, how to add the custom list view class into my viewlet.
Here are my viewlet url patterns:
^api/channel/$ [name='channel-list']
^api/channel/(?P<pk>[^/]+)/$ [name='channel-detail']
^api/channel/(?P<pk>[^/]+)/all_events/$ [name='channel-all-events']
^api/channel/(?P<pk>[^/]+)/now_and_next_event/$ [name='channel-now-and-next-event']
And I would like to access my list view like:
^api/channel/current_events/$ [name='event-current']