Re: [SQLObject] How do ForeignKeys work?
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Ian B. <ia...@co...> - 2004-08-27 15:47:39
|
paul wrote: > Hi, > > I have to classes like so: > > CaCert(CertItem): > SignedCerts = MultipleJoin('Cert') > ... > > Cert(CertItem): > CA = ForeignKey('CaCert') > Type = StringCol() > ... > > def _set_Type(self, value): > _valid = ['email', 'client', 'object', 'server'] > if value not in _valid: > raise ValueError('Type must be one of %s' % _valid) > elif CA.Type not in ['ca_'+value, 'ca_root']: > raise ValueError('CA must support cert type %s.' % type) > self._SO_set_Type(value) The bug is here: CA isn't defined (just like the exception says). Maybe you mean self.CA.Type? That might not work either. In SQLObject in SVN you could do something like: def _create(self, id, **kw): if kw['CA'].Type not in ['ca_' + kw['Type'], 'ca_root']: raise ValueError, ... super(Cert, self)._create(id, **kw) def _set_Type(self, value): _value = ... if value not in _valid: ... if not self._SO_creating and self.CA.Type not in ...: self._SO_set_Type(value) -- Ian Bicking / ia...@co... / http://blog.ianbicking.org |