models.py
class Wishlist(models.Model):
home = models.ForeignKey(Home, on_delete=models.CASCADE, blank=False, null=False)
user = models.ForeignKey(User, on_delete=models.CASCADE, blank=False, null=False)
def __str__(self):
return "{} - {}".format(self.user.username, self.home.address)
class Meta:
ordering = ('user',)
urls.py
urlpatterns = [
path(r'wishlist/<int:pk>/', views.WishlistGetUserItems.as_view(), name='wish-user-list'),
]
views.py
class WishlistGetUserItems(APIView):
def get(self, request, pk):
wishlist = get_list_or_404(Wishlist, user=pk)
data = serializers.UserWishlistSerializer(wishlist).data
Response(data, status=status.HTTP_200_OK)
I've tried also to print message but seems like the method is not called
You should add return before Response.
def get(self, request, pk):
wishlist = get_list_or_404(Wishlist, user=pk)
data = serializers.UserWishlistSerializer(wishlist).data
return Response(data, status=status.HTTP_200_OK)
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