
## ==== "tg-admin shell" -- how TG does C.R.U.D.
##
from pprint import pprint

Category._connection.debug = True       ## dump generated SQL  

Category.get(1)                         # get a Cat obj by ID

res = Category.select(Category.q.name == "All")

Category._connection.debug = False

list( res )

cat = res[0]                            ## (only) row -- "All" Category-obj

print cat.description

for res in cat.select():  print(res)    ## dump all Category objects

pprint( cat.subcategories )

# define "alternateID" to get "unique" (searchable) columns

catw = cat.byName("Worm")               ## another Category object
print catw

catw.description = "Worm Gearing"       ## print this...


catp = Category(name="Planetary", description="Planetary Gears", \
		parent=cat)

prodp = Product(name="Epicyclic", description="Epicyclic gearing",
                category=catp)

print catp.products

pprint( cat.subcategories )


catb = cat.byName("Bevel")               ## another Category object

print catb.subcategories

print catb.products
print len( catb.products )

prb = catb.products[0]                  # get the (1) Bevel-gears product

pprint( prb.items )                     # print all the items of this Product



list( Product.select( Product.q.categoryID == catb.id ) )

list( Product.select( Product.q.categoryID > 1 ) )

#  http://sqlobject.org/SQLObject.html#exported-symbols

from sqlobject.sqlbuilder import *

list( Product.select(LIKE(Product.q.name, "%Helical%")) )

Product.delete(prodp)
print catp.products

## ==== "tg-admin shell"

