From: Dan Weeks <danimal@wi...> - 2006-02-15 20:01:30
From reading the FAQ I was trying to do an _init method in my classes like so:
name = StringCol(length=30)
parent = RelatedJoin('NarrativeElement',
children = RelatedJoin('NarrativeElement',
yada = StringCol(length=40)
def addSubordinate(self, instance):
foo = StringCol(length=30)
superior = ForeignKey('Superior')
def _init(self, id):
Basically I'm trying to have a child add itself to a parent. Now, the three
questions I have are:
1) since the _init method is called on insert or fetch does that mean that
"self.superior.addSubordinate(self)" would be called every time it's fetched?
2) I can just call self.addParent(self.superior) but that won't work for
some of the data checking we're trying to do (not shown) where one
Subordinate can be subordinate to more than one Superior-type class. Would
that be a better solution though? If so I could re-factor for it I'm sure.
3) would it be ideal to override the _set_superior method instead? In any
case I can't seem to get something like this to work at all:
def _set_superior(self, value):
I'm wondering if it's that superior is a ForeignKey. Is there something
special I need to do?
Thanks for any pointers. I'm still pretty new to SQLObject so I'll take any
criticism and pointers you might have.