直接cmd下运行 pip3 install python-memcached
serializer.py 里的特别应用
如果一个表模型一些字段用到了跨表。可以这样取值
跨表字段 coach_nickname = serializers.CharField(source='coachinfo.nickname')
可以获取多个选项的字段:sort = serializers.CharField(source='get_course_type_display')
class Meta:
model = models.Course
fields = ['id','name','sort','coach_nickname']
manytomany 反向查找型:
price_policy = serializers.SerializerMethod()
def get_policy_policy(self,obj):
price_policy_list = price_list.objects.all()
return [{'id':row.id,'itemname':row.itemname} for row in price_policy_list]