title: Which methods should be overridden to implement automatic locking and unlocking records in Django
body: <p>How can I modify the behaviour of models in Django to perform automatic locking and unlocking records in database on selecting them and make this behaviour transparent for a programmer? I already know how to lock and unlock a record (<a href="https://stackoverflow.com/questions/2335953/database-record-locking/2335981#2335981">database record locking</a>) but we'd like to know where this code should be placed in Django models. I'd like it to work for every all(), filter(), exclude() and other queries, and unlocking should be invoked while save() and also in queries in which we don't save anything.</p>
  
  <p><strong>UPDATE</strong>: This application has several threads that can be run by two or more servers simultaneously and I want to ensure that no records from a common database would be processed by more than one thread. Threads search for some records and then send some data through sockets and finally update these records. In other words, besides Django website there are servers.</p>