Lucas
Lucas

Reputation: 1279

NameError: name '(Whatever)' is not defined

This error is driving me crazy.

I'm developing an App Engine Python application. These are the classes:

from google.appengine.ext import db

class Usuario(db.Model):
  user = db.UserProperty()
  nombre = db.StringProperty(required = True)
  pasaporte = db.ReferenceProperty(Pasaporte)

class Pasaporte(db.Model):
  direccion = db.StringProperty()
  telefono = db.PhoneNumberProperty()

class Sindicato(db.Model):
  nombre = db.StringProperty(required = True)
  direccion = db.StringProperty()
  telefono = db.PhoneNumberProperty()

class Sede(db.Model):
  nombre = db.StringProperty()
  direccion = db.StringProperty()
  telefono = db.PhoneNumberProperty()
  descripcion = db.StringProperty()

class Servicio(db.Model):
  nombre = db.StringProperty()
  descripcion = db.StringProperty()
  prestador = db.StringProperty()
  condiciones = db.StringListProperty()

class UsuarioServicio(db.Model):
  usuario = db.ReferenceProperty(Usuario, collection_name='servicios_collection')
  servicio = db.ReferenceProperty(Servicio, collection_name='usuario_collection')
  fechaRegistro = db.DateTimeProperty(auto_now_add=True)

I don't know why but this is the error message I get when trying to test my application in localhost:

NameError: name 'Pasaporte' is not defined

In UsuarioServicio class I'm referencing to other classes without getting any error.

If helps, I'm working in Kubuntu 10-10 on Eclipse-Pydev with Python2.7 interpreter. Anyway, if I try to launch the application from terminal through 'dev_appserver.py'command, the error is displayed anyway.

What is wrong with my code?

Upvotes: 0

Views: 2045

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599600

Pasaporte isn't declared until after it is used in Usario. Switch the order of those classes and it will be fine.

Upvotes: 3

Related Questions