错误:model()缺少1个必需的位置参数:“ request”
我想为我的应用程序中的所有模型做抽象api
urls.py
urlpatterns = [
path('api/object/', views.GeneralViewSet.as_view({'get': 'list'}))
]
views.py
class GeneralViewSet(viewsets.ModelViewSet):
@property
def model(self, request):
return apps.get_model(app_label=self.request.data.get('app'),
model_name=self.request.data.get('object'))
def get_queryset(self, request):
return self.model.objects.all()
def get_serializer_class(self, request):
GeneralSerializer.Meta.model = self.model
return GeneralSerializer
def post(self, request):
queryset = self.model.objects.all()
serializer = self.get_serializer(queryset, many=True)
return Response(serializer.data)
我希望我的模型数据列表
例如
的post api{
"app": "leads",
"object": "Lead"
}
从Lead对象中查看所有数据