擅长:python、mysql、java
<p>您可以使用<strong>getqueryset</strong>方法,如果您知道更多信息,请参阅doc<a href="http://www.django-rest-framework.org/api-guide/filtering/" rel="noreferrer">Filtering against the current user </a></p>
<pre><code>class AllProgramsApi(ModelViewSet):
serializer_class = ProgramSerializer
queryset = Program.objects.all()
def get_queryset(self):
queryset = self.queryset
query_set = queryset.filter(user=self.request.user)
return query_set
</code></pre>