<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Random Musings of an Insane Mind &#187; recursive</title>
	<atom:link href="http://cd34.com/blog/tag/recursive/feed/" rel="self" type="application/rss+xml" />
	<link>http://cd34.com/blog</link>
	<description>This is my blog, there are many others like it but this one is mine.</description>
	<lastBuildDate>Tue, 29 Jun 2010 04:22:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Recursive Category Table in Python</title>
		<link>http://cd34.com/blog/programming/python/recursive-category-table-in-python/</link>
		<comments>http://cd34.com/blog/programming/python/recursive-category-table-in-python/#comments</comments>
		<pubDate>Sat, 13 Jun 2009 16:16:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[category table]]></category>
		<category><![CDATA[recursive]]></category>

		<guid isPermaLink="false">http://cd34.com/blog/?p=650</guid>
		<description><![CDATA[While working with a project, the problem with the recursive category table being built came up. The table holds the parent_id of the category name and the result is a list with the id and the name of the category. The category name is prepended with spaces equivalent to the level of indentation. model: class [...]]]></description>
			<content:encoded><![CDATA[<p>While working with a project, the problem with the recursive category table being built came up.  The table holds the parent_id of the category name and the result is a list with the id and the name of the category.  The category name is prepended with spaces equivalent to the level of indentation.</p>
<p>model:</p>
<pre>
class AchievementCategory(DeclarativeBase):
	__tablename__ = 'achievement_categories'

	id = Column(mysql.MSBigInteger(20, unsigned = True), primary_key = True)
	parent_id = Column(mysql.MSBigInteger(20, unsigned = True), default = 0)
	name = Column(Unicode(80))
</pre>
<p>code:</p>
<pre>
def get_cats(n = 0, c_list = [], level = 0):
	sql = DBSession.query(AchievementCategory).filter_by(parent_id = n).order_by(AchievementCategory.name).all()
	for e in sql:
		c_list.append([e.id, level * " " + e.name, level])
		get_cats(e.id, c_list, level+1)
	return c_list

print get_cats()
</pre>
]]></content:encoded>
			<wfw:commentRss>http://cd34.com/blog/programming/python/recursive-category-table-in-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
