We want to create a migration to change the datatype of a column while keeping the data that already exists in the database. We can’t just change the column datatype in-place and (auto-)create a migration for that. That would corrupt the existing data in the database. Here is how to do the change the datatype while preserving the existing data.
Changing a column datatype without loosing data using SQLAlchemy and Alembic
Authentication with Django REST Framework
In this post I will go through some common authentication mechanisms that are used with Django REST Framework (DRF). Some of these methods are included in DRF, and the others are custom authentication packages that implement popular schemes not included in DRF. We will go through how each scheme works and when it should be used. I have also included some resources for learning how to implement each.
Creating custom manage.py commands
For my recent project pyremote, I needed to run a script every night to remove old job postings from the database. I decided to implement it as a custom manage.py command so that I can easily run it from command line and add it to a nightly cron job on the server.
Dockerizing a Django + PostgreSQL project
In this guide I show you how to run your Django app in one Docker container and your PostgreSQL database in another and make them talk to each other. We are going to manage and run these two containers using Docker Compose.
Dockerizing a Django + MySQL project
If you are here, I assume you have already embraced the merits of using Docker to set up your development environment such that it matches your staging and production environments. In this guide I show you how to run your Django app in one Docker container and your MySQL database in another and make them talk to each other. We are going to manage and run these two containers using Docker Compose.
3 tips for overcoming Django's learning curve
Do you feel that learning Django was harder than you anticipated? Or that even though you have followed some tutorials, you still don’t have a grasp over what Django does? and how?
Validating Django models that are created without forms
Usually instances of models (objects) are created using a
ModelForm. You know the drill: The user inputs some values in the form, hits submit and sends a
POSTrequest with the data. In the view function, we do a model validation using
form.is_valid()and then save the object in the database. This gives a basic level of validation for the model fields.
Including static files in Django templates