title: Problem in importing classes from models file in GAE
body: <p>I am very new to python and after a brief intro on to python + Google app engine, I've started to work on a pilot project. I have bulkloaded 2 entities UserDetails and PhoneBook with data onto the app engine. Now in my UI I try to first take in the user name then query it to get the user id from UserDetails, then using the retrieved user id I query the PhoneBook to get the his phone book entries. Here's my code for the UI,</p>
  
  <pre><code>#!/usr/bin/env python
  
  import wsgiref.handlers
  from google.appengine.ext import db
  from google.appengine.ext import webapp
  from google.appengine.ext.webapp import template
  from models import UserDetails,PhoneBook
  #import models
  
  class showPhoneBook(db.Model):
      """ class to store the user_name to db """
      user_name = db.StringProperty(required=True)
  
  class MyHandler(webapp.RequestHandler):
      def get(self):
          """ Query type 1 """
          #p = db.GqlQuery('SELECT * FROM UserDetails WHERE user_name = :1', user_name)
  
          """ Query type 2 """
          #p = UserDetails.gql('WHERE user_name = :1', user_name)
  
          """ Query type 3 """
          p = UserDetails.all().filter('user_name = ', user_name)
          result1 = p.get()
          for itr1 in result1:
              userId = itr.user_id
  
          """ Query type 1 """    
          #q = db.GqlQuery('SELECT * FROM PhoneBook WHERE user_id = :1', userId)
  
          """ Query type 2 """
          #q = PhoneBook.gql('WHERE user_id = :1', userId)
  
          """ Query type 3 """
          q = PhoneBook.all().filter('user_id = ', userId)
          values = {
              'phoneBookValues': q
          }
          self.response.out.write(
              template.render('phonebook.html', values))
      def post(self):
          phoneBookuserID = showPhoneBook(
              user_name = self.request.get('username'))
          phonebookuserID.put()
          self.redirect('/')
  
  def main():
      app = webapp.WSGIApplication([
          (r'.*',MyHandler)], debug=True)
      wsgiref.handlers.CGIHandler().run(app)
  
  if __name__ == "__main__":
      main()
  </code></pre>
  
  <p>The problem is that I get this error in my logs that GAE can't import the UserDetails/phone class from models,</p>
  
  <pre><code>&lt;type 'exceptions.ImportError'&gt;: cannot import name UserDetails
  Traceback (most recent call last):
    File "/base/data/home/apps/bulkloader160by2/1-4.337299749289926105/main.py", line 7, in &lt;module&gt;
      from models import UserDetails,PhoneBook
  </code></pre>
  
  <p>and when I remove <code>from models import UserDetails,PhoneBook</code> and use <code>import models</code>, I get,</p>
  
  <pre><code>global name 'UserDetails' is not defined
  Traceback (most recent call last):
    File "/base/python_lib/versions/1/google/appengine/ext/webapp/__init__.py", line 507, in __call__
      handler.get(*groups)
    File "/base/data/home/apps/bulkloader160by2/1-4.337300095868541686/main.py", line 19, in get
      p = UserDetails.all().filter('user_name = ', user_name)
  NameError: global name 'UserDetails' is not defined
  </code></pre>
  
  <p>This is my models.py file where I've my UserDetails and PhoneBook classes defined. I've stored this file in the root directory.</p>
  
  <pre><code>#!/usr/bin/env python
  
  from google.appengine.ext import db
  
  #Table structure of User Details table
  class UserDetails(db.Model):
    user_id = db.IntegerProperty(required = True)
    user_name = db.StringProperty(required = True)
    mobile_number = db.PhoneNumberProperty(required = True)
  
  #Table structure of Phone Book table
  class PhoneBook(db.Model):
    contact_id = db.IntegerProperty(required=True)
    user_id = db.IntegerProperty(required=True)
    contact_name = db.StringProperty(required=True)
    contact_number = db.PhoneNumberProperty(required=True)
  </code></pre>
  
  <p>Being new to python I am not able to figure out why am not able to import my classes from my models.py file and how to set/get the user_name from <code>post(self)</code> to <code>get(self)</code>.</p>
  
  <p>Please forgive me if I'm being naive but your help is most appreciated if you can help me in  setting my code right.</p>
  
  <p>Thanks.</p>