[storm] Defining relationships between classes

Gerdus van Zyl gerdusvanzyl at gmail.com
Fri Aug 8 16:00:16 BST 2008


The NameError: name 'Card' is not defined exception means Card is not
in the current namespace.

In examplemodel.py modify
import examplemodel
to
from examplemodel import Card

or
card = Reference(card_id, Card.id)
to
card = Reference(card_id, examplemodel.Card.id)

You also have a circular reference Card to Example and Example to Card
, in my experience you will have to lazy define one half of that like:
invoice = Reference(invoiceno, 'invoice.invoiceno')
instead of
invoice = Reference(invoiceno, invoice.invoiceno)

~Gerdus

On Fri, Aug 8, 2008 at 6:40 AM, Alexei Vinidiktov
<alexei.vinidiktov at gmail.com> wrote:
> 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
>
> --
> storm mailing list
> storm at lists.canonical.com
> Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/storm
>



More information about the storm mailing list