25. MODEL FIELD
➤ Field options
➤ null=True v.s. blank=True
➤ CharField & TextField only need to use blank=True
➤ default
➤ choices
➤ ex: status
➤ help_text
➤ unique
➤ db_index
➤ db_column
26. MODELS
➤ Relationship fields
➤ ForeignKey
➤ Many-to-one relationships
➤ ManyToManyField
➤ OneToOneField
Book
Category Tag
1
m m
n
27. MIGRATIONS
➤ makemigrations & migrate
➤ sqlmigrate, which displays the SQL statements for a
migration.
➤ ex: python manage.py sqlmigrate books 0001
➤ showmigrations, which lists a project’s migrations and their
status.
➤ New in 1.10
➤ python manage.py migrate —list (before 1.10)
28. ADMIN
➤ createsuperuser
➤ Password - It must contain at least 8 characters. (1.10)
➤ admin.py
➤ @admin.register(Book)
➤ admin.site.register(Book)
➤ __str__ method
30. ADMIN 中⽂文化 - PART I
➤ settings.py
➤ LANGUAGE_CODE = 'zh-hant'
31.
32. MODEL META
➤ Model Meta options
➤ db_table
➤ default: books_book
➤ ordering
➤ ex: ordering = [‘-published']
➤ unique_together
➤ ex: unique_together = (("name", "author"),)
➤ ManyToManyField cannot be included in
unique_together
33. ADMIN 中⽂文化 - PART II
➤ Model Meta options
➤ verbose_name & verbose_name_plural
34.
35. ADMIN 中⽂文化 - PART III
➤ books/apps.py
➤ books/__init__.py
36.
37. ADMIN 中⽂文化 - PART IV
➤ Model Field options
➤ verbose_name