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()

語法總結

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章