title: How to monkey patch Django?
body: <p>I came upon this <a href="http://www.alrond.com/en/2008/may/03/monkey-patching-in-django/">post</a> on monkey patching Django:</p>
  
  <pre><code>from django.contrib.auth.models import User
  
  User.add_to_class('openid', models.CharField(max_length=250,blank=True))
  
  def get_user_name(self):
      if self.first_name or self.last_name:
          return self.first_name + " " + self.last_name
      return self.username
  
  User.add_to_class("get_user_name",get_user_name)
  </code></pre>
  
  <p>I understand that this isn't ideal and it's better to add fields and functions to <code>User</code> through a separate model <code>Profile</code>.</p>
  
  <p>With that said, I just want to understand how this would work:</p>
  
  <ol>
  <li><p>Where would I put the monkey patching code?</p></li>
  <li><p>When is the code run -- just once? once per Python interpreter startup? once per request?</p></li>
  <li><p>Presumably I'd still need to change the DB schema. So if I dropped the table <code>User</code> and ran <code>./manage.py syncdb</code>, would <code>syncdb</code> "know" that a new field has been added to <code>User</code>? If not how do I change the schema?</p></li>
  </ol>