尝试获取序列化程序scrumgoal_set
上的字段ScrumUserSerializer
的值时出现此错误:
/ p / scrumusers / 中的AttributeError
序列化程序字段的名称可能不正确,并且可能与ScrumUser
实例上的任何属性或键都不匹配。
原始异常文本为:
“ ScrumUser”对象没有属性“ scrumgoal_set”。
serializer.py
from .models import *
from rest_framework import serializers
class UserSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = ['username','groups','password',]
class ScrumGoalSerializer(serializers.ModelSerializer):
class Meta:
model = ScrumyGoals
fields = ['goal_id','goal_name','goal_status']
class ScrumUserSerializer(serializers.ModelSerializer):
scrumgoal_set = ScrumGoalSerializer(many=True)
class Meta:
model = ScrumUser
fields = ['nickname', 'id','scrumgoal_set']
class ScrumProjectRoleSerializer(serializers.ModelSerializer):
# user = ScrumUserSerializer()
# scrumgoal_set = ScrumGoalSerializer(many=True)
class Meta:
model = ScrumProjectRole
fields = ('role', 'user', 'id')