[storm] Defining relationships between classes

Alexei Vinidiktov alexei.vinidiktov at gmail.com
Fri Aug 8 05:40:13 BST 2008


Hello,

I'm just getting started with Storm. I'm also somewhat new to Python.
I want to define relationships between two classes: Card and Example.
Each Card may have multiple Examples. I have my classes located in the
following directory hierarchy:

main.py
models
--- cardmodel.py
--- examplemodel.py

When I execute the main.py script I get this error:

Traceback (most recent call last):
  File "C:\Alexei\wxPython\Boa\wxSpacedRepetition\wxSpacedRepetition.py",
line 2, in <module>
    from models.cardmodel import *
  File "C:\Alexei\wxPython\Boa\wxSpacedRepetition\models\cardmodel.py",
line 3, in <module>
    import examplemodel
  File "C:\Alexei\wxPython\Boa\wxSpacedRepetition\models\examplemodel.py",
line 7, in <module>
    class Example(object):
  File "C:\Alexei\wxPython\Boa\wxSpacedRepetition\models\examplemodel.py",
line 14, in Example
    card = Reference(card_id, Card.id)
NameError: name 'Card' is not defined

I'd be grateful if you would give me a pointer as to what's wrong with my code.
My lack of good knowledge of Python may be preventing me from seeing
the cause of the problem.

Thanks.

Here are the contents of my python files:

#main.py
#------------
from models.cardmodel import *

card = Card()

#cardmodel.py
#-------------------
from storm.locals import *
import examplemodel

"""This class represents a Card Model"""

class Card(object):
    __storm_table__ = "cards"
    id = Int(primary=True)
    question = Unicode()
    answer = Unicode()
    comment = Unicode()
    examples = ReferenceSet(id, Example.card_id)

#examplemodel.py
#-------------------------
from storm.locals import *
import cardmodel

"""This class represents an Example Model"""

class Example(object):
    __storm_table__ = "examples"
    id = Int(primary=True)
    example = Unicode()
    translation = Unicode()
    comment = Unicode()
    card_id = Int()
    card = Reference(card_id, Card.id)

-- 
Alexei Vinidiktov



More information about the storm mailing list