[Answer]-TastyPie resources

1👍

Finally figured it out. The solution is…. ugh. Anyhow, here it is:

def prepend_urls(self):
    return [
        url(r"^(?P<resource_name>%s)/(?P<pk>\d+)/channels%s$" % (self._meta.resource_name, trailing_slash()), self.wrap_view('get_channels'), name="api_get_channels"),
    ]

def get_channels(self, request, **kwargs):
    basic_bundle = self.build_bundle(request=request)
    obj = self.cached_obj_get(bundle=basic_bundle, **self.remove_api_resource_names(kwargs))
    channel_resource = UserChannelResource()
    try:
        channel_resource._meta.queryset = obj.channels.all()
    except IndexError:
        channel_resource._meta.queryset = Channel.objects.none()

    return channel_resource.get_list(request)

Leave a comment