models
With django default ORM, we can easily control database's data, without traditional way to access it.
More effective, safty, and easy.
Different application can have it own model define data field.
# System/models.py
from django.db import models
class system_test(models.Model):
name = models.CharField(max_length=20)
And this is a basic model in database a table named 'systemtest' with only single field which is 'name'
also, this field defaultly has a primary key called 'pk', the field has only one paremeter which is max_length.
For further model filed to use. you can check the following url:
https://docs.djangoproject.com/en/2.0/ref/models/fields/
Every time you edit a models.py always comes with a pair of command to execute.
# python manage.py makemigrations
# python manage.py migrate
ORM helps developer to construce entire database, before system do the reall change of it.
Developer should use makemigrations to commit to the ORM, let ORM organize every table/field whom may effect by this change.
Once the ORM checked the migrations is valid. Developer can us migrate to confirm the operation,
and let ORM do the migrate job.
Be advice, this doesn't mean after makemigrations, ORM can 100% migrate changes.
Especially some operation involve with ForiegnKey.