REST_framework属性

时间:2019-03-27 03:01:53

标签: python django django-rest-framework django-views

尝试获取序列化程序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')

0 个答案:

没有答案