Alexandr Domoryonok Alexandr Domoryonok - 2 years ago 284
Python Question

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

So I refer to another model :

subscriptions = models.ManyToManyField(Season)

So I use :

def buy_season(request):
_id = 1
season = Season.objects.get(id = _id)

a = ExtUser.subscriptions.add(season)

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 Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download