My Models.py
from django.db import models
from vendor.models import *
from django.db import models
class UserSignUp(models.Model):
u_fname = models.CharField(max_length=30)
u_lname = models.CharField(max_length=30)
u_email = models.CharField(max_length=50)
u_password = models.TextField()
class Cart (models.Model):
userId = models.ForeignKey(UserSignUp , on_delete=models.CASCADE )
productId = models.ForeignKey(addProduct , on_delete=models.CASCADE)
qty = models.IntegerField(null=True)
date = models.DateTimeField()
views.py
getCart = Cart.objects.filter(userId_id = pk ).values()
msg = {
‘getCart’ : getCart,
}
return Response(msg)
In React
but i want to show all addProduct & UserSignUp Model Data how to do that ?
so i can show productImages , prices , user name , user address etc etc
You have at least three different options that I can think of off-hand:
Dear Sir i did it like this please let me know is it a correct way or not if not then tell me whats the correct way i will be grateful to you
dataArray =
for i in range( len(getCart) ) :
dataArray.append(getCart[i])
# print( "productId_id - ", dataArray[i]['productId_id'] )
users = UserSignUp.objects.filter(id = dataArray[i]['userId_id'] ).values()
convertedUsers = list( users )
dataArray[i].__setitem__("userKey", convertedUsers )
product = addProduct.objects.filter(id = dataArray[i]['productId_id'] ).values()
convertedProduct = list( product )
# print("174 - convertedUsers- ", convertedProduct )
dataArray[i].__setitem__("productKey", convertedProduct )
msg = {
'msg' : "ProductAddedInCart",
"cartFullArray" : dataArray
}
return Response(msg)
There’s no one “right way” or “wrong way” to do this. If it works for you, it’s probably good enough for now.