当我过滤公司的仓库时,它返回错误:
RecursionError: maximum recursion depth exceeded in comparison
def destroy(self, request, *args, **kwargs):
company = Company.objects.get(owner=self.request.user)
stores = Store.objects.filter(company=company.id)
if len(stores) <= 1:
return Response(data={'detail': 'At least one storehouse is required'}, status=status.HTTP_400_BAD_REQUEST)
return self.delete(request, *args,**kwargs)
答案 0 :(得分:0)
如果您使用的是DestroyAPIView
,则调用self.delete()
会将其返回到destroy method。而不是self.delete()
,您应该调用super方法。
def destroy(self, request, *args, **kwargs):
company = Company.objects.get(owner=self.request.user)
stores = Store.objects.filter(company=company.id)
if len(stores) <= 1:
return Response(data={'detail': 'At least one storehouse is required'}, status=status.HTTP_400_BAD_REQUEST)
return super().destroy(request, *args,**kwargs)