我正在尝试进行迁移,但是我遇到了一个问题。我收到错误消息:
queryset = Data_Point.objects.all()
AttributeError: type object 'Data_Point' has no attribute 'objects'
,我不确定为什么。我已经搜索了错误,但仍然找不到灵魂。错误可以在models.py类中吗?具体来说,问题可能出在与每个表和外键的关联上吗?以下是以下类:
models.py
class System(models.Model):
System = models.CharField(max_length=255)
def __str__(self):
return self.System
class Sub_System(models.Model):
Sub_System = models.CharField(max_length=255)
System = models.ForeignKey(System, on_delete=models.CASCADE)
def __str__(self):
return self.Sub_System
class Data_Name(models.Model):
Data_Name = models.CharField(max_length=255)
Sub_System = models.ForeignKey(Sub_System, on_delete=models.CASCADE)
def __str__(self):
return self.Data_Name
class Data_Point(models.Model):
Captured_Timestamp = models.DateTimeField(auto_now_add=False, blank=True)
Inserted_Timestamp = models.DateTimeField(default=datetime.now, blank=True)
Data_Value = models.CharField(max_length=4)
Data_Name = models.ForeignKey(Data_Name, on_delete=models.CASCADE)
def __str__(self):
return self.Data_Value
views.py
class SystemView(viewsets.ModelViewSet):
queryset = System.objects.all()
serializer_class = SystemSerializer
class Sub_SystemView(viewsets.ModelViewSet):
queryset = Sub_System.objects.all()
serializer_class = Sub_SystemSerializer
class Data_NameView(viewsets.ModelViewSet):
queryset = Data_Name.objects.all()
serializer_class = Data_NameSerializer
class Data_PointView(viewsets.ModelViewSet):
queryset = Data_Point.objects.all()
serializer_class = Data_PointSerializer
serializers.py
class SystemSerializer(serializers.ModelSerializer):
class Meta:
model = System
fields = ('id', 'System')
class Sub_SystemSerializer(serializers.ModelSerializer):
class Meta:
model = Sub_System
fields = ('id', 'Sub_System', 'System')
class Data_NameSerializer(serializers.ModelSerializer):
class Meta:
model = Data_Name
fields = ('id', 'Data_Name', 'Sub_System')
class Data_Point(serializers.ModelSerializer):
class Meta:
model = Data_Point
fields = ('id', 'Captured_Timestamp', 'Inserted_Timestamp', 'Data_Value', 'Data_name')