Python ';ManyToManyDescriptor';对象没有属性';添加';,为什么?

Python ';ManyToManyDescriptor';对象没有属性';添加';,为什么?,python,django,Python,Django,因此,我指的是另一种模式: subscriptions = models.ManyToManyField(Season) 因此,我使用: @api_view(['POST']) def buy_season(request): _id = 1 season = Season.objects.get(id = _id) a = ExtUser.subscriptions.add(season) a.save() return Response({'

因此,我指的是另一种模式:

 subscriptions = models.ManyToManyField(Season)
因此,我使用:

@api_view(['POST'])
def buy_season(request):
    _id = 1
    season = Season.objects.get(id = _id)

    a = ExtUser.subscriptions.add(season)

    a.save()

    return Response({'status': 'success'}, status=status.HTTP_200_OK)
我得到一个错误对象“ManyToManyDescriptor”没有属性“Add”
直接进行多对多操作,而不是通过“投掷”,出现此错误的原因?

您应该使用
ExtUser
模型的实例,因为您无法将模型对象直接添加到类对象。

是否
ExtUser
是您模型的实例?@MosesKoledoye With ExtUser I重写了user@MosesKoledoye“订阅”字段属于ExtUserName。您只能添加对象指向模型的实例,而不是类对象。@MosesKoledoye现在我盯着文本看,明白了,谢谢。我得睡觉了:)