0

I have my test model :

from shop import db
    
    
class Product(db.Model):
  id = db.Column(db.Integer, primary_key=True)
  name = db.Column(db.String(50), unique=True, nullable=False)
  price = db.Column(db.Float, nullable=False)
  description = db.Column(db.Text, nullable=False, unique=True)

I create the db, add product, commit :

db.create_all()
from shop.models import Product
p1 = Product(name='p1', price=120.55, description='<h1>tag</h1>')
db.session.add(p1)
db.session.commit()

but when I query the data I get this:

Product.query.all()
>>> [<Product 1>]
6
  • What is the problem you have? Commented May 24, 2021 at 10:15
  • I wanna have an object not a <class 'list'> Commented May 24, 2021 at 10:32
  • I ve seen tutorial where they put the same query and they get a list (Array) of products Commented May 24, 2021 at 10:33
  • 1
    The square brackets you see are Python's way of printing a list, the item inside it is printed however the object wants to be printed via its __str__ method (in this case it prints the object type and ID). What you have is a list containing one object. Commented May 24, 2021 at 11:21
  • 1
    If you only want one "thing" then perhaps try .one() instead of .all() Commented May 24, 2021 at 12:18

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.