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 ?
You should use an instance of the ExtUser
model as you cannot add a model object directly to a class object.
User instance instead of class.
a = ExtUser.objects.get(id=user_id).subscriptions.add(season)
You need to update the above query and it will fix the issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With