Django REST框架 - 找不到嵌套的序列化程序

时间:2014-10-25 18:13:39

标签: python json django serialization django-rest-framework

我正在使用django-rest-framework并注意到嵌套序列化程序的问题。我被告知找不到我的序列化程序对象。我的代码和回溯如下:

房间/ serializers.py

class RoomSerializer(serializers.ModelSerializer):
    name = serializers.CharField(max_length=255)
    type = RoomTypeSerializer()
    clinic_location = serializers.Field(source='clinic_location')
    status = RoomStateTypeSerializer()
    url = serializers.CharField(max_length=100, default="room")

    class Meta:
        model = Room

访问/ serializers.py

from clinic.serializers import *
from patient.serializers import *
from room.serializers import *
from service.serializers import *
from transition.serializers import *
from userprofile.serializers import *

class SubvisitSerializer(serializers.ModelSerializer):
    visit = VisitSerializer()
    room = RoomSerializer()
    service = ServiceSerializer()
    transition = TransitionSerializer()
    status = SubVisitStateSerializer()
    patient = PatientSerializer()
    clinic_location = ClinicLocationSerializer()

    class Meta:
        model = Subvisit

回溯:

File "/Users/Zee/Repos/patient-flow/visit/serializers.py" in SubvisitSerializer
  51.   room = RoomSerializer()
Exception Value: name 'RoomSerializer' is not defined

非常感谢任何帮助。

干杯,

Zee的

1 个答案:

答案 0 :(得分:0)

感谢@dreysecat和@mariodev。

@mariodev,尝试明确导入序列化程序,但没有运气。然而,它对我的​​导入声明敲响了警钟,我认为发生了某种奇怪的事情。

我将序列化程序移动到另一个位置,然后从那里导入它。通过回溯进行了一些阅读,但意识到有一个嵌套的序列化程序导致了这个问题。

谢谢,

Zee的