Posts tagged django

Django Links

Django related links

Read more ...


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 ...


Nested Serialization in Django REST Framework

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.

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 ...


Register Django Model in Admin

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.

Read more ...


Setup Django for Testing with pytest

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.

Read more ...


Django Testing Cookbook

In this cookbook we are focusing on testing Django with pytest.

Read more ...


Setup the Project for Django REST Framework

Install Django REST Framework and implement Swagger interface for the API.

Read more ...


Generate Database Diagram from Django Models

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.

Read more ...


Django REST Framework Cookbook

This cookbook looks into working with APIs built on Django using Django REST Framework.

Read more ...


Django ORM Cookbook

With this cookbook we dive into Django ORM.

Read more ...


Debug Django Project with Visual Studio Code (VSCode)

In order to debug Django project, we need to first create a Visual Studio Code (VSCode) run configuration.

Read more ...


Setup a New Django Project

Start a new Django project from scratch.

Read more ...


Core Django Cookbook

This cookbook provides solutions for creating, managing and developing django projects.

Read more ...


Django Cookbook

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.

Read more ...