Posts tagged core

Custom Sequential Number Django Model Field

Sometimes we need certain functionality again, and again, and again,… Sometimes it just makes sense to encapsulate certain logic into a separate module so it is easier to test and maintan. For example, we might need Django model field that is capable of keeping seqential number of the items in the order they are stored in the database.

Read more ...


Setting Up Fake Django Application for Testing with Pytest

Sometimes we need to test our code in a context of a Django application. Usually this code implements generic components, e.g. custom Django fields. We could always test our components in the context of our Django application, but this breaks the requirement for test isolation. To overcome this problem we could create a Django application which is intended for testing the specific components.

Read more ...


Enable Database Lock Timeout in Django

By default clients requesting database lock should wait until the lock is released. This might take forever. In locking contention situations it might be useful to instrument your database to timeout when lock is not being released for given amount of time, e.g. 5 seconds.

Read more ...


Log Django SQL Queries to Terminal

Sometimes you might need to be able to log Django SQL queries. You might want to print them to the terminal or send them to a remote logging system. In this example I show you how to create Django middleware which logs the SQL queries executed by HTTP session to the terminal.

Read more ...