I’m working on a Django REST Framework project where I have a Cart model, and I want to allow authenticated users to add items to their cart via a POST request. However, I keep getting the following error: ValueError: Cannot query "admin": Must be "User" instance. Here’s the relevant part of my Cart model: class Cart(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='carts') album = models.ForeignKey(Album, on_delete=models.CASCADE) quantity = models.PositiveIntegerField(default=1) added_at = models.DateTimeField(default=timezone.now) And here’s the CartView where the issue occurs: class CartView(APIView): permission_classes = [IsAuthenticated] def post(self, request): user = User.objects.get(id=request.user.id) # Force correct User instance album_id = request.data.get('album_id') if not album_id: return Response({"error": "Album ID is required"}, status=400) try: album = Album.objects.get(id=album_id) except Album.DoesNotExist: return Response({"error": "Album does not exist"}, status=404) cart_item, created = Cart.objects.get_or_create(user=user, album=album) if not created: cart_item.quantity += 1 cart_item.save() return Response({"message": f"Added {album.title} to cart", "quantity": cart_item.quantity}, status=201) In Postman, I include the Authorization header with a valid token: Authorization: Token fcbb7230bb0595694200e3e6effbe67d1c43fb7c Ensured request.user is properly authenticated. Verified that the token belongs to the correct user in the admin panel. Logged type(request.user) and found it’s not always an instance of User. Explicitly retrieved the User instance using User.objects.get(id=request.user.id). Continue reading...