标签:type sed nbsp highlight related one 序列 返回值 eth
在获取序列化返回值时候想要有时候我们需要生成我们需要的关联字段
class CourseSerializers(ModelSerializer): # 对于外键,one to one , choice 可以用这种source方式 course_type =serializers.CharField(source=‘get_course_type_display‘) class Meta: model = Course fields = [‘id‘,‘name‘,‘course_type‘] # fields = ‘__all__‘ class CourseDetaileSerializers(HyperlinkedModelSerializer): # teachers = HyperlinkedRelatedField(many=True,view_name=‘teacher-detaile‘,read_only=True) # 对于多对多复杂字段,或者外键取多个字段 prices = SerializerMethodField() question = SerializerMethodField() course_detail = SerializerMethodField() teachers = SerializerMethodField() recommend_courses = SerializerMethodField() course_chapter= SerializerMethodField() comment = SerializerMethodField()
标签:type sed nbsp highlight related one 序列 返回值 eth
原文地址:https://www.cnblogs.com/zjchao/p/8889209.html