title: Django ORM select_related AttributeError
body: <p>In my project im trying to use an external .py file for manage data using my django app style like this:</p>
  
  <p>In my django project i create a model:</p>
  
  <pre><code>class temp_test_keywords(models.Model):
      main_id = models.ForeignKey(temp_main)
      test_id = models.ForeignKey(temp_case)
      key_id = models.ForeignKey(temp_keywords)
      variable_id = models.ForeignKey(temp_variables, null=True, blank=True)
  
      def __str__(self):
          return '%s -&gt; %s' % (str(self.main_id), str(self.test_id))
  </code></pre>
  
  <p>Well, now in my external rst.py file i start django env like this:</p>
  
  <pre><code>import sys
  import os
  import django
  
  sys.path.append('core')
  os.environ['DJANGO_SETTINGS_MODULE'] = 'core.settings'
  django.setup()
  </code></pre>
  
  <p>ok, at this point i import table and create class for do some thinks with it:</p>
  
  <pre><code>from django.db import models
  from django.contrib.contenttypes.fields import 
  GenericForeignKey,GenericRelation
  from django.contrib.contenttypes.models import ContentType
  from django.db.models import Count
  
  from frontend.models import temp_test_keywords
  
  
  class PrepareRst:
      def __init__(self,test_id,t_type,log=False):
          self.rst = self.mainprep(test_id,t_type)
  
      def mainprep(self,test_id,t_type): 
          return self.tc_prep(test_id)
  
      #TestCase rst prep method
      def tc_prep(self,test_id):
          maxpar = temp_test_keywords.objects.filter(main_id = test_id).values('key_id').annotate(total=Count('variable_id')).order_by('-total').first()
          totpar = maxpar['total']
  
          #Part1 list creation
          count = 0
          ltouple = ()
          l1 = ["Test Case"]
          while (count &lt; totpar):
              l1.append("")
              count += 1
          ltouple += (l1,)
          #Query for extract keywords, values
          kv = temp_test_keywords.select_related()
  </code></pre>
  
  <p>but when i run an <strong>AttributeError: type object 'temp_test_keywords' has no attribute 'select_related'</strong> error raise</p>
  
  <p>if i start python manage.py shell from terminal the "kv = temp_test_keywords.select_related()" command works fine, why in my .py code doesn't?</p>
  
  <p>Thanks in advance</p>