Class CompanySerializers missing“Meta.model”attribute我一直在使用Django Rest Api Framework制作API,每当我运行我的应用程序时,它都会显示上述错误。
我的Serializers.py:
from rest_framework import serializers
from api.models import Company
# Create Serializers here
class CompanySerializers(serializers.HyperlinkedModelSerializer):
class Meta:
model: Company
fields = "__all__"
我的model.py:
from django.db import models
# Create your models here.
#Creating Company model
class Company(models.Model):
company_id = models.AutoField(primary_key= True)
name = models.CharField(max_length=50)
location = models.CharField(max_length= 50)
about = models.TextField()
type = models.CharField(max_length= 100, choices=
(('IT','IT'), ('Non IT', 'Non_IT'), ('Mobiles_phones', 'Mobiles_phones')))
added_Date = models.DateTimeField(auto_now=True)
active = models.BooleanField(default=True)
我的views.py:
from django.shortcuts import render
from rest_framework import viewsets
from api.models import Company
from api.serializers import CompanySerializers
# Create your views here.
class CompanyViewSet(viewsets.ModelViewSet):
queryset = Company.objects.all()
serializer_class = CompanySerializers
我已经尝试了一切,但无法解决它。请大家看看这个,这将是非常有帮助的。
1条答案
按热度按时间m4pnthwp1#
你有
它是一个具有
fields
属性和注解的类,该注解将属性model
指定为Company
类型。你需要
所以有一个类有两个属性
model
和fields
。IOW,一个单个字符的错别字:
:
应该是=
。