Re: [SQLObject] Reimplements the constructor...
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: <mic...@ya...> - 2004-07-20 17:31:09
|
Hi Luke! > I may be misunderstanding you, is article.title a ForeignKey to title > that may > be NULL (when the title comes from article.section)? If so, from a > database > perspective I would not duplicate the data to set article.title = > article.section.title. If section.title changes, then you need more > application code to correctly update the article title, etc. > > Instead, transparently retrieve the section's title if the article > has no > title: Hugh, oh yeah, I done something with my idea, but your idea is better, maybe :) I coding a system to store and search my country laws, see, the tree can be: - law - title - section - subsection - article or only: - law - title - article I done some code, and it´s working for me, look: class Container: def createParentObjects(self, kw): _containers=['law', 'title', 'section', 'subsection', 'article'] class_name=self.__class__.__name__.lower() index=_containers.index(class_name) containers=_containers[:index] # first i count how many containers was passed to the constructor l=[kw.has_key(x) for x in containers] if l.count(1)!=1: raise TypeError, 'You can pass only one container!' index=l.index(1) # there is only one index to element 1 key=containers[index] # then I create the antecessors for container in containers[:index]: kw[container]=kw[key].__getattribute__(container) return kw class Title(SQLObject, SubContainer): ... def __init__(self, **kw): SQLObject.__init__(self, **self.createParentObjects(kw)) This way I don´t need to rewrite all the constructors with the same code, but I have the problem that I can´t change the article´s place... I will try to implement a way using the _get_attribute idea... thanks for all help :) ===== -- Michel Thadeu Sabchuk Curitiba/PR _______________________________________________________ Yahoo! Mail agora com 100MB, anti-spam e antivírus grátis! http://br.info.mail.yahoo.com/ |