Django Tips #22 Designing Better Models

In this post, I will share some tips to help you improve the design of your Django Models. Many of those tips are related to naming conventions, which can improve a lot the readability of your code. The PEP8 is widely used in the Python ecosystem (Django included). So it’s a good idea to use it in your own projects. Besides PEP8, I like to follow Django’s Coding Style which is a guideline for people writing code for inclusion in the Django code base itself. Below, an overview of the items we are going to explore: Naming Your Models Model...

How to Create Django Data Migrations

Data Migration is a very convenient way to change the data in the database in conjunction with changes in the schema. They work like a regular schema migration. Django keep track of dependencies, order of execution and if the application already applied a given data migration or not. A common use case of data migrations is when we need to introduce new fields that are non-nullable. Or when we are creating a new field to store a cached count of something, so we can create the new field and add the initial count. In this post we are going to...