Using Django ORM as a standalone
Django is one of the popular python frameworks; critiques have argued that it is a bloated framework. The truth of the matter is that it is very modularized, and each of the components () can be independently used. In this article, we will attempt to use the Django ORM component to deploy a production database that natively supports migrations (most ORM’s lack this concept, and you sometimes really need to invest time to implement it using libraries such as Alembic). Django provides this out of the box, so let’s go ahead and use it.
- Create a new project
mkdir test && cd test
2. Create a requirements.txt and add
django
3. Create a virtual env, enter virtual env and install all dependencies
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
4. Create your app location at the root of the project.
mkdir app # You can use any name
5. In your app directory, create the models.py file and add the following code to your models.py
from django.db import modelsclass User(models.Model):
firstname = models.CharField(max_length=100)
lastname = models.CharField(max_length=100)