lundi 25 juillet 2016

'ManyToManyDescriptor' object has no attribute 'add', why?

So I refer to another model :

 subscriptions = models.ManyToManyField(Season)

So I use :

@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)

I get an error object 'ManyToManyDescriptor' does not attribute the "Add" Do many to many directly , and not through the " throw " , why there is this error ?

Aucun commentaire:

Enregistrer un commentaire