Alexandr Domoryonok Alexandr Domoryonok - 5 months ago 21
Python Question

'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 ?

Answer

You should use an instance of the ExtUser model as you cannot add a model object directly to a class object.

Comments