You want "notNull=True" instead of "notNone=True".
On Thu, 23 Feb 2006, Max Ischenko wrote:
I have an SQLObject model class like this: class ResourceAccessRule(SQLObject): ... action = ForeignKey('ResourceAction', notNone=True, title="Action") resource = ForeignKey('Resource', notNone=True, title="Resource") I used notNone=True to hint SQLObject that this field is required but in vain:ResourceAccessRule(action=None, resource=None)File "c:\python24\lib\site-packages\sqlobject-0.7.1dev_r1547-py2.4.egg\sqlobject\mysql\mysqlconnection.py", return cursor.execute(query) File "C:\Python24\lib\site-packages\MySQLdb\cursors.py", line 137, in execute self.errorhandler(self, exc, value) File "C:\Python24\lib\site-packages\MySQLdb\connections.py", line 33, in defaulterrorhandler raise errorclass, errorvalue OperationalError: (1048, "Column 'action_id' cannot be null") Is there a way to enforce non-None values in ctor? So far I resorted to: def _create(self, id, **kw): if not kw.get('action'): raise ValueError('No action given') if not kw.get('resource'): raise ValueError('No resource given') super(ResourceAccessRule, self)._create(id, **kw) Is there a better way? Thanks, Max. ------------------------------------------------------- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd_______________________________________________ sqlobject-discuss mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
------------------------------------------------------- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642 _______________________________________________ sqlobject-discuss mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
