I'm using django-rest-framework and noticing an issue with the nesting serializers. I'm being told that my serializer object isn't found. My code and traceback are below:
room/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
visit/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
Traceback:
File "/Users/Zee/Repos/patient-flow/visit/serializers.py" in SubvisitSerializer
51. room = RoomSerializer()
Exception Value: name 'RoomSerializer' is not defined
Any help is much appreciated.
Cheers,
Zee
Thanks @dreysecat and @mariodev.
@mariodev, tried explicitly importing the serializer but didn't have any luck. It however ring a bell about my import statements, I think there was some kind of strange happening.
I moved the serializer to another location, and imported it from there. Took a bit of reading through the traceback, but realized there were a nested serializer that was causing the problem.
Thanks,
Zee
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.