I recently wanted to tweak how a model was being saved, so I used the _pre_save method of it. In the _pre_save method I needed to use the gethostbyaddr and herror of the socket module. To my surprise, I got problems [1] when having "from socket import gethostbyaddr, herror" in module-level. It worked, however, when I moved the from ... import ... statement *inside* the _pre_save method.
Is there a restriction on importing stuff in your app's models module? And if yes, is there a reason for this? Thanks! [1]: From the debug output I got, it looked like Django was unable to find gethostbyaddr and herror in the namespace. Like I had never imported them?!