Posts in django
Custom Sequential Number Django Model Field
- 01 October 2023
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.
Setting Up Fake Django Application for Testing with Pytest
- 30 September 2023
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.
Nested Serialization in Django REST Framework
- 16 September 2023
In case you are serializing a model with relationships the default ModelSerializer behavior is to provide the primary key of the relationship target. In case you need to serialize the target object not just the primary key, you have (at least) two options: explicit nested serializer and implicit nested serializer using depth.
Enable Database Lock Timeout in Django
- 14 September 2023
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.
Log Django SQL Queries to Terminal
- 14 September 2023
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.
Register Django Model in Admin
- 11 September 2023
There are multiple methods to register a model in Django admin. I will show you how to register a single model (one by one for multiple), all the models in an application and all the models in the project.
Setup Django for Testing with pytest
- 10 September 2023
Test Driven Development is a popular software development practice which helps in creating better software. The practice that I prefer is a little bit relaxed practice that I call Test Assisted Development as sometimes tests are not written before the production code (but let’s leave this discussion for another place and time). Django projects also need to be thoroughly tested. Let’s configure our Django project for testing with pytest before even creating the first Django application.
Django Testing Cookbook
- 10 September 2023
In this cookbook we are focusing on testing Django with pytest.
Setup the Project for Django REST Framework
- 09 September 2023
Install Django REST Framework and implement Swagger interface for the API.
Generate Database Diagram from Django Models
- 09 September 2023
Database diagram are very useful project documentation. They might be useful for understanding the project. With projects under development, documentation, diagrams are not exception, easily gets out of sync with actual implementation. Generating documentation from code helps to keep the documentation always up to date with the current code.
Django REST Framework Cookbook
- 09 September 2023
This cookbook looks into working with APIs built on Django using Django REST Framework.
Debug Django Project with Visual Studio Code (VSCode)
- 09 September 2023
In order to debug Django project, we need to first create a Visual Studio Code (VSCode) run configuration.
Core Django Cookbook
- 09 September 2023
This cookbook provides solutions for creating, managing and developing django projects.
Django Cookbook
- 09 September 2023
Welcome to this Django Cookbook (YADC - Yet Another Django Cookbook). The goal of this cookbook is to systematize and answer common questions when working with Django. The intention is to put some more advanced techniques, but to get to advanced discussions, we have to provide some context and start with some basics.