title: How do you reload a Django model module using the interactive interpreter via "manage.py shell"?
body: <p>I know how to reload a regular Python module within a regular Python interpreter session. This question documents how to do that pretty well:</p>
  
  <p><a href="https://stackoverflow.com/questions/437589/how-do-i-unload-reload-a-python-module">How do I unload (reload) a Python module?</a></p>
  
  <p>For some reason, I am having trouble doing that within Django's "manage.py shell" interpreter session. To recreate my issue, start the basic Django tutorial found here:</p>
  
  <p><a href="http://docs.djangoproject.com/en/dev/intro/tutorial01/" rel="nofollow noreferrer">Writing your first Django app, part 1</a></p>
  
  <p>After creating the "polls" application and "Poll" class, start up the interpreter via "manage.py shell" and import the "polls" app into it.</p>
  
  <pre><code>import polls.models as pm
  </code></pre>
  
  <p>Create a new "Poll" object:</p>
  
  <pre><code>p = pm.Poll()
  </code></pre>
  
  <p>All is well and good so far. Now go back to your source and add any arbitrary method or attribute. For example, I've added:</p>
  
  <pre><code>def x(self):
      return 2+2
  </code></pre>
  
  <p>Now go back to the interpreter and "reload" the module:</p>
  
  <pre><code>reload(pm)
  </code></pre>
  
  <p>Now try to use your new method or attribute:</p>
  
  <pre><code>p1 = pm.Poll()
  p1.x()
  </code></pre>
  
  <p>You'll get this message:</p>
  
  <pre><code>'Poll' object has no attribute 'x'
  </code></pre>
  
  <p>What gives? I've also tried rerunning the import command, importing the module using different syntax, deleting all references to any "Poll" objects or to the "Poll" class. I've also tried this with both the IPython interpreter and with the plain Python (v2.6) interpreter. Nothing seems to work.</p>
  
  <p>Using the same techniques with an arbitrary Python module in a regular interpreter session works perfectly. I just can't seem to get it to work in Django's "shell" session.</p>
  
  <p>By the way, if it makes any difference, I'm doing this on a Ubuntu 9.04 machine.</p>