swagger 属性错误:"QuerySet"对象没有属性"model"

lx0bsm1f  于 2023-02-08  发布在  其他
关注(0)|答案(1)|浏览(134)

我想添加Django应用的文档
1.我使用的是休息框架mongoengine

  1. OpenAPI 3.0,drf-壮观的 Swagger
    • 型号:**
from mongoengine import *

class Service(Document):
    student_id = StringField(required=True)
    name = StringField(max_length=50)
    age = IntField()
    • 串行化程序:**
from Service.models import Service
from rest_framework_mongoengine import serializers as mongoserializers

class ServiceSerializer(mongoserializers.DocumentSerializer):
    class Meta:
        model = Service
        fields = '__all__'
    • 浏览次数:**
import mongoengine
from .models import Service
from rest_framework import generics
from .serializers import ServiceSerializer
from .docs import list_service, create_service, update_service, delete_service
from rest_framework_mongoengine.viewsets import ModelViewSet as MongoModelViewSet

mongoengine.connect(db='Ecommerce', host='localhost:27017')

@create_service()
class CreateServiceAPI(generics.CreateAPIView):
    queryset = Service.objects.all()
    serializer_class = ServiceSerializer

我创建了文档,但当我执行文档中的任何端点时,会发生此错误
"属性错误:"QuerySet"对象没有属性"model"

任何人都能帮我解决这个问题

bnl4lu3b

bnl4lu3b1#

更改模型以添加字段:

from django_mongoengine import Document, fields

class Service(Document):
    student_id = fields.StringField(blank=True)
    name = fields.StringField(max_length=50)
    age = fields.IntField()

相关问题