1、filter_queryset
class ProductAdd(generics.ListCreateAPIView):
queryset = Product.objects.all()
serializer_class = ProductSerializer
filter_fields = ("status", "sale_supplier")#传入参数过滤
template_name = "product_add.html"
permission_classes = (permissions.IsAuthenticated,)
def get(self, request, *args, **kwargs):
queryset = self.filter_queryset(self.queryset)#根据参数进行过滤
page = self.paginate_queryset(queryset)
……
Authentication
授权
Auth needs to be pluggable.
认证需要是可插拔的!!
— Jacob Kaplan-Moss, "REST worst practices"
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-12-28 20:18:38