From: David M. <da...@re...> - 2004-03-24 14:20:29
|
Hi, I'm posting here in the hope that my problem, and its solution, might save others from the battle I've had. Basically, I'm implementing a web shopping cart. While I was tempted to have just a plain 2 or 3 level product hierarchy, this felt too restrictive and I wanted a more general solution - the ability to have an unrestricted n-level hierarchy of product categories. After some experimenting and reading SQLObject source, the following solution came out: class prodcats(SQLObject): _connection = _conn name=StringCol() longname=StringCol() parent=ForeignKey('prodcats', default=None) children=MultipleJoin('prodcats', joinColumn='parent_id') prodcats.createTable() rPets = prodcats.new( name='pets', longname='Pets') rBirds = prodcats.new( name='birds', longname='Birds', parent=rPets) rLargeBirds = prodcats.new( name='large', longname='Large Birds', parent=rBirds) rSmallBirds = prodcats.new( name='small', longname='Small Birds', parent=rBirds) rDogs = prodcats.new( name='dogs', longname='Dogs', parent=rPets) rLargeDogs = prodcats.new( name='large', longname='Large Dogs', parent=rDogs) rSmallDogs = prodcats.new( name='small', longname='Small Dogs', parent=rDogs) -- Kind regards David -- |