我有一个使用Django rest创建的REST API。我收到以下错误:
AttributeError: type object 'ContactRequestSerializer' has no attribute 'get_extra_actions'
class ContactRequestSerializer(serializers.ModelSerializer):
class Meta:
model = ContactRequest
fields = '__all__'
class ContactFormSerializer(serializers.ModelSerializer):
class Meta:
model = ContactForm
fields = '__all__'
class ProjectRequestSerializer(serializers.ModelSerializer):
class Meta:
model = ProjectRequest
fields = '__all__'
我在所有序列化程序中都指定了相同的属性,并且我从同一个类继承而来,但是问题仍然存在。
我有一个API文件,可在其中创建视图集
class ContactFormViewSet(viewsets.ModelViewSet):
queryset = ContactForm.objects.all()
permission_classes = [
permissions.AllowAny
]
serializer_class = ContactFormSerializer
# ProjectRequest Viewset
class ProjectRequestViewSet(viewsets.ModelViewSet):
queryset = ProjectRequest.objects.all()
permission_classes = [
permissions.AllowAny
]
serializer_class = ProjectRequestSerializer
class ContactRequestViewSet(viewsets.ModelViewSet):
queryset = ContactRequest.objects.all()
permission_classes = [
permissions.AllowAny
]
serializer_class = ContactRequestSerializer
然后是我的模型:
...
class ContactRequest(models.Model):
topic = models.CharField(max_length=30)
description = models.CharField(max_length=200)
time = models.CharField(max_length=15)
project_request = models.ForeignKey(ProjectRequest, on_delete=models.CASCADE)
由于它们看起来都很相似,除了我的两个模型之间的关系之外,我无法弄清楚这个问题。