Advertisement
Guest User

Untitled

a guest
Nov 21st, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. from pony.orm import *
  2.  
  3. db = Database()
  4.  
  5.  
  6. class Product(db.Entity):
  7.     id = PrimaryKey(int, auto=True)
  8.     name = Required(str)
  9.     stars = Optional(IntArray)
  10.     tags = Optional(StrArray)
  11.  
  12.  
  13. db.bind('sqlite', ':memory:')
  14. db.generate_mapping(create_tables=True)
  15.  
  16. with db_session:
  17.     product = Product(name='abc', stars=[1, 2, 3], tags = ['qwe'])
  18.     tags = select(p.stars[:3] for p in Product)[:]#ok
  19.     print(tags)
  20.     end = 3
  21.     tags = select(p.stars[:end] for p in Product)[:]#TypeError: Array indices should be type of int
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement