title: Django import error: No module named models
body: <p>I keep receiving the error <code>Could not import movies.views. Error was: No module named models</code></p>
  
  <p>Here is my traceback:</p>
  
  <pre><code>    Environment:
  
  
      Request Method: GET
      Request URL: http://localhost:8000/movies/awesome-movie/
  
      Django Version: 1.3.1
      Python Version: 2.7.3
      Installed Applications:
      ['django.contrib.auth',
       'username_patch',
       'django.contrib.contenttypes',
       'django.contrib.sessions',
       'django.contrib.sites',
       'django.contrib.messages',
       'django.contrib.staticfiles',
       'django.contrib.admin',
       'django.contrib.flatpages',
       'south',
       'tagging',
       'tagging_autocomplete',
       'accounts',
       'movies',
       'tracking',
       'djcelery',
       'pagination']
      Installed Middleware:
      ('django.middleware.common.CommonMiddleware',
       'django.contrib.sessions.middleware.SessionMiddleware',
       'django.middleware.csrf.CsrfViewMiddleware',
       'django.contrib.auth.middleware.AuthenticationMiddleware',
       'django.middleware.locale.LocaleMiddleware',
       'django.contrib.messages.middleware.MessageMiddleware',
       'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
       'pagination.middleware.PaginationMiddleware')
  
  
      Traceback:
      File "/Users/jeff/Code/filmlibrary/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
        101.                             request.path_info)
      File "/Users/jeff/Code/filmlibrary/lib/python2.7/site-packages/django/core/urlresolvers.py" in resolve
        252.                     sub_match = pattern.resolve(new_path)
      File "/Users/jeff/Code/filmlibrary/lib/python2.7/site-packages/django/core/urlresolvers.py" in resolve
        252.                     sub_match = pattern.resolve(new_path)
      File "/Users/jeff/Code/filmlibrary/lib/python2.7/site-packages/django/core/urlresolvers.py" in resolve
        158.             return ResolverMatch(self.callback, args, kwargs, self.name)
      File "/Users/jeff/Code/filmlibrary/lib/python2.7/site-packages/django/core/urlresolvers.py" in _get_callback
        167.             raise ViewDoesNotExist("Could not import %s. Error was: %s" % (mod_name, str(e)))
  
      Exception Type: ViewDoesNotExist at /movies/awesome-movie/
      Exception Value: Could not import movies.views. Error was: No module named models
  </code></pre>
  
  <p>I am not sure why I have this error. My code is as follows...</p>
  
  <p>I have an django app called <code>tracking</code> and another called <code>movies</code>. I have a python file called <code>tracking.py</code> in the <code>tracking</code> app it consists of the following code:</p>
  
  <p><strong>filmlibrary/tracking/tracking.py</strong></p>
  
  <pre><code>from movies.models import Movie
  from tracking.models import MovieView
  
  import os
  import base64
  
  def tracking_id(request):
      try:
          return request.session['tracking_id']
      except KeyError:
          request.session['tracking_id'] = base64.b64encode(os.urandom(36))
          return request.session['tracking_id']
  
  def log_movie_view(request, movie):
      t_id = tracking_id(request)
      try:
          v = MovieView.objects.get(tracking_id=t_id, movie=movie)
          v.save()
      except MovieView.DoesNotExist:
          v = MovieView()
          v.movie = movie
          v.ip_address = request.META.get('REMOTE_ADDR')
          v.tracking_id = t_id
          v.user = None
          if request.user.is_authenticated():
              v.user = request.user
          v.save()
  </code></pre>
  
  <p>The above is pretty basic stuff. My <code>views.py</code> in my <code>movies</code> app uses the tracking.py file here:</p>
  
  <p><strong>filmlibrary/movies/views.py</strong></p>
  
  <pre><code>@login_required
  def movie_details(request, slug, template_name="movies/movie_detail.html"):
      movie = get_object_or_404(Movie, slug=slug)
      movie.tracking_id = tracking.tracking_id(request)
      movie.save()
      tracking.log_movie_view(request, movie)
      context = RequestContext(request, {'movie': movie })
      if movie:
          try:
              screener = movie.moviemedia_set.get(movie_type='screener')
              .... continued
  </code></pre>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Here are the contents of filmlibrary/tracking/models.py</p>
  
  <pre><code>from django.db import models
  from django.contrib.auth.models import User
  
  from movies.models import Movie
  
  class PageView(models.Model):
      class Meta:
          abstract = True
  
      date = models.DateTimeField(auto_now=True)
      ip_address = models.IPAddressField()
      user = models.ForeignKey(User, null=True)
      tracking_id = models.CharField(max_length=50, default='')
  
  class MovieView(PageView):
      movie = models.ForeignKey(Movie)
  </code></pre>
  
  <p>The error appears to come from the import line <code>from tracking.models import MovieView</code> in the tracking.py file and I am not sure why. As soon as I comment out that line the error goes away but then of course I'll have new errors about MovieView not existing as expected. I don't see anything wrong with that import line in tracking.py.</p>
  
  <p>Does anyone have any suggestions as to why I receive that error and how I can resolve this?</p>