我使用Serializer创建一个Django REST API,但是如果我测试序列化器,我只收到一个空结果。
其实我应该收到
>>> from heating.serializers import RoomSerializer
>>> s = RoomSerializer()
>>> print(repr(s))
RoomSerializer():
... LIST OF FIELDS WITH SOME ADDITIONAL INFOMRATION...
>>>
模型
class Room(models.Model):
id = models.IntegerField(auto_created=True, primary_key=True)
name = models.CharField(max_length=100, blank=True, default='')
description = models.TextField()
class Meta:
ordering = ['id']
串行
class RoomSerializer(serializers.ModelSerializer):
class Meta:
model = Room
fields = ('id', 'name', 'description')
外壳输出
>>> from heating.serializers import RoomSerializer
>>> s = RoomSerializer()
>>> print(repr(s))
RoomSerializer():
>>>
我强烈相信,我的代码中存在错误,但我不知道在哪里?