If I write this order for AddressRegionDetailSerializer
and AvailableAreaSerializer
:
class AddressRegionDetailSerializer(ModelSerializer):
"""
地域详情(包含可用区域)
"""
availableareas = AvailableAreaSerializer(many=True, read_only=True)
class Meta:
model = AddressRegion
fields = "__all__"
class AvailableAreaSerializer(ModelSerializer):
"""
可用地区
"""
class Meta:
model = AvailableArea
fields = "__all__"
There will report NameError issue:
NameError: name 'AvailableAreaSerializer' is not defined
in this line:
availableareas = AvailableAreaSerializer(many=True, read_only=True)
So, I must put the AvailableAreaSerializer
in the front.
But however in my idea, I want to write the Serializer as the Models order, I don't want to break this law.
So, is there a simple way to maintain this order?