UserRegistrationAPIView应该包含“ querylist”属性,或覆盖“ get_querylist()”方法

时间:2019-06-15 12:53:46

标签: django-rest-framework django-views

am试图创建一个与android应用程序通信的API,同时尝试实现用户注册,我使用了django自定义用户模型,成功对其进行了序列化,但由于#app / Views代码而有点丢失 对django很新

class UserRegistrationAPIView(ObjectMultipleModelAPIView):
    def get_query_list(self):
        query_list = ({'queryset':      ClientUser.objects.all(),
                       'serializer_class':        UserClientRegSeerializer},
                      {'queryset': User.objects.all(),
                       'serializer_class': UserRegistrationSerializer}

                  )
        return query_list

class UserRegistrationAPIView(ObjectMultipleModelAPIView):

    def get_query_list(self):
        query_list = ({'queryset':      ClientUser.objects.all(),
                       'serializer_class':        UserClientRegSeerializer},
                      {'queryset': User.objects.all(),
                       'serializer_class': UserRegistrationSerializer}

                  )
        return query_list

1 个答案:

答案 0 :(得分:2)

According to the documentation,您无需覆盖任何方法。您需要做的就是定义一个名为 querylist 的属性。

class UserRegistrationAPIView(ObjectMultipleModelAPIView):
    querylist = [{'queryset': ClientUser.objects.all(),
                  'serializer_class': UserClientRegSeerializer},
                 {'queryset': User.objects.all(),
                  'serializer_class': UserRegistrationSerializer}

                 ]


class FooUserRegistrationAPIView(ObjectMultipleModelAPIView):
    querylist = [{'queryset': ClientUser.objects.all(),
                  'serializer_class': UserClientRegSeerializer},
                 {'queryset': User.objects.all(),
                  'serializer_class': UserRegistrationSerializer}

                 ]

注意:在OP中,您两次定义了 UserRegistrationAPIView 类,这可能是一个错误。