Hi, I have the following model (in turbogears, but I think the problem is
pure SQLObject) (only relevant parts copied):

----------------------------------------------------
class Photo(SQLObject):
       filename = StringCol(length=30,alternateID=True)
       keywords = RelatedJoin('Keyword')
       [etc...]

class Keyword(SQLObject):
       keyword = StringCol(alternateID=True)
       photo = RelatedJoin('Photo')
------------------------------------------------------

Now I want to try the following. I want Photo to accept a string of
keywords, and then add these keywords to the foto. I tried adding the
following method to Photo, but it gives me an error:

------------------------------------------------------
       def _set_keywords(self,value):
               # accepts value as a string. Multiple keywords should be
comma-seperated
               keywords = value.split(',')
               for keyword in keywords:
                       keyword = keyword.strip()
                       try:
                               ref = Keyword.byKeyword(keyword)
                       except SQLObjectNotFound:
                               ref = Keyword(keyword=keyword)
                       self.addKeyword(ref)
-----------------------------------------------------

And the traceback:

----------------------------------------------------
Page handler: <bound method Root.import_photos of
<photon.controllers.Root object at 0x01559370>>
Traceback (most recent call last):
 File "p:\python25\lib\site-packages\cherrypy-2.2.1-py2.5.egg\cherrypy
\_cphttptools.py", line 105, in _run
   self.main()
 File "p:\python25\lib\site-packages\cherrypy-2.2.1-py2.5.egg\cherrypy
\_cphttptools.py", line 254, in main
   body = page_handler(*virtual_path, **self.params)
 File "<string>", line 3, in import_photos
 File "p:\python25\lib\site-packages\TurboGears-1.0.2.2-py2.5.egg
\turbogears\controllers.py", line 336, in expose
   *args, **kw)
 File "<string>", line 5, in run_with_transaction
 File "p:\python25\lib\site-packages\TurboGears-1.0.2.2-py2.5.egg
\turbogears\database.py", line 303, in so_rwt
   retval = func(*args, **kw)
 File "<string>", line 5, in _expose
 File "p:\python25\lib\site-packages\TurboGears-1.0.2.2-py2.5.egg
\turbogears\controllers.py", line 351, in <lambda>
   mapping, fragment, args, kw)))
 File "p:\python25\lib\site-packages\TurboGears-1.0.2.2-py2.5.egg
\turbogears\controllers.py", line 378, in _execute_func
   output = errorhandling.try_call(func, *args, **kw)
 File "p:\python25\lib\site-packages\TurboGears-1.0.2.2-py2.5.egg
\turbogears\errorhandling.py", line 73, in try_call
   return func(self, *args, **kw)
 File "F:\Dev\Python\Photon\photon\controllers.py", line 54, in
import_photos
   res = Photos.import_photos(photos,options)
 File "F:\Dev\Python\Photon\photon\model.py", line 130, in
import_photos
   copyright=copyright)
 File "p:\python25\lib\site-packages\SQLObject-0.9.0b2-py2.5.egg
\sqlobject\declarative.py", line 94, in _wrapper
   return fn(self, *args, **kwargs)
 File "p:\python25\lib\site-packages\SQLObject-0.9.0b2-py2.5.egg
\sqlobject\main.py", line 1214, in __init__
   self._create(id, **kw)
 File "p:\python25\lib\site-packages\SQLObject-0.9.0b2-py2.5.egg
\sqlobject\main.py", line 1242, in _create
   self.set(**kw)
 File "p:\python25\lib\site-packages\SQLObject-0.9.0b2-py2.5.egg
\sqlobject\main.py", line 1106, in set
   setattr(self, name, value)
 File "F:\Dev\Python\Photon\photon\model.py", line 52, in
_set_keywords
   self.addKeyword(1)
 File "<string>", line 1, in <lambda>
 File "p:\python25\lib\site-packages\SQLObject-0.9.0b2-py2.5.egg
\sqlobject\joins.py", line 223, in add
   getID(inst),
 File "p:\python25\lib\site-packages\SQLObject-0.9.0b2-py2.5.egg
\sqlobject\joins.py", line 15, in getID
   return int(obj)
TypeError: int() argument must be a string or a number, not 'Photo'

--------------------------------------------------------------------------------------------------------


I did a little debugging, the add function in sqlobject\joins.py looks
like this:
------------------------------------------------------------------
   def add(self, inst, other):
       inst._connection._SO_intermediateInsert(
           self.intermediateTable,
           self.joinColumn,
           getID(inst),
           self.otherColumn,
           getID(other))
---------------------------------------------------------------------
debugging shows that it receives
<Photo (not initialized)> as inst, and <Keyword 1 keyword='test'> as
other.
It also sees self.addKeyword in my model as a lambda - <bound method
Photo.<lambda> of <Photo (not initialized)>>. I am unable to find that
lambda however, and I don't know how to fix this.
Any clues?

TiNo
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to