Django note2
·User model
The User model is already defined inside a built-in app named auth, which is listed in our INSTALLED_APPS configuration under the namespace django.contrib.auth.
·models
-in models.py ,each class will be transformed into database tables.
-Each field is represented by instances(实例) of django.db.models.Field subclasses (built-in Django core) and will be translated into database columns.(转换为数据表中的一列)
-use
python manage.py makemigrations
python manage.py sqlmigrate boards 0001
创建sql语句 python manage.py migrate
创建表
-create new object
board = Board(name='Django', description='This is a board about Django.')
To persist this object in the database, we have to call the save method:
board.save()
-special attribute
Every Django model comes with a special attribute; we call it a Model Manager. You can access it via the Python attribute objects Board.objects.all()
Board.objects.get()
Board.objects.create()