# 序列化角色
class RoleSerializer(serializers.ModelSerializer):
class Meta:
model = models.Role
fields = '__all__'
# 序列化规则
class RuleSerializer(serializers.ModelSerializer):
#查询所有规则信息,包括角色
roles = RoleSerializer(many=True, read_only=True)
class Meta:
model = models.Rule
fields = '__all__'
#查询所有规则对应的角色
class Rule_Role_View(APIView):
def get(self,request):
# 查询所有规则对应的角色
ruleobj = models.Rule.objects.all()
guize = RuleSerializer(ruleobj, many=True)
if guize:
return Response({
'status':200,
'msg':'',
'data':guize.data
})
return Response({
'status': 201,
'msg': '网络错误,请稍后重试',
'data': ''
})