title: why is django code snip running in models file?
body: <p>In django.contrib.auth.models.py, there is a function with a line under it at the top starting on 20</p>
  
  <pre><code>def update_last_login(sender, user, **kwargs):
      """
      A signal receiver which updates the last_login date for
      the user logging in.
      """
      user.last_login = timezone.now()
      user.save()
  user_logged_in.connect(update_last_login)
  </code></pre>
  
  <p>This last line looks weird to me, because it is calling a function, immediately after the definition. I've never considered calling a models.py file like it's a script, and I thought the django models are nothing more than definitions...when does this user_logged_in line get called? On any import of the models file, or what? If it only gets called when users log in, how does django know to only call it then? Thanks</p>