Radon333
Radon333

Reputation: 122

How to Retrieve a specific value of a Tuple from Django database

Product table

So here I have a table named Product which contains Food name,Category,Price,Image,Dataset id column so i would like to retrieve the value of Dataset id only ,in Django

I would like to put parse dataset_id into recommend function but it doesnt give value of 31 while i select Pizza so i tried just printing it and the output in my console is <django.db.models.query_utils.DeferredAttribute object at 0x03B11CE8>

here is my code from views.py

from .models import Product
def cart(request):

if request.user.is_authenticated:
print(Product.dataset_id)
res=recommend(item_id=31, num=3)
customer = request.user.customer
order , created = Order.objects.get_or_create(customer = customer , complete=False)
items = order.orderitem_set.all()
cartItems = order.get_cart_items
print(res)

Here is my code for Products in models.py

class Product(models.Model):
food_id = models.AutoField
food_name = models.CharField(max_length=50, default="")
cateory = models.CharField(max_length=50, default="")
subcategory = models.CharField(max_length=50, default="")
price = models.IntegerField(default=0)
image = models.ImageField(upload_to='menu/images', default="")
dataset_id = models.IntegerField(default = 0)

Upvotes: 0

Views: 358

Answers (1)

Chandan Kumar Manna
Chandan Kumar Manna

Reputation: 21

You need to first get the Product whose dataset_id you want to print. You can do that by using pk value or any other unique attributes. i.e : product = Product.objects.get(pk=pk) print(product.dataset_id)

Upvotes: 1

Related Questions