Django is an open source model-View-Controller (MVC)-style WEB application framework that is driven by the Python programming language. With Django, we can create high-quality, maintainable, database-driven applications within minutes. Now let's take a look at how you can use the database in Django:Common data Types Autofield: int self-added, parameters must be passed in Primary_keyBigautofield: bigint, you must pass in the parameter Primary_keySmallintegerfield: Small Integer seriesIntegerfield: Whole seriesPositiveintegerfield: Positive integer SeriesBigintegerfield: Large integer SeriesBooleanfield: Boolean columnsNullbooleanfield: A Boolean column that can be emptyCharfield: Character type, max_length must be passed inTextField: Text TypeIntegerfield: Whole seriesFloatfield: Floating-point typeDecimalfield: Decimal Decimal. Parameters:
max_digits: Total decimal lengthdecimal_places: Length of decimal placesImageField: string, path saved in database, file uploaded to specified directory, parameters:
upload_to= "" Upload to specified pathStorage= None Storage component, default Django.core.files.storage.FileSystemStorageWidth_field= None Upload the width of the picture saved database field nameHeight_field= None upload picture's height saved database field nameDatetimefield: Date + time. Format: YYYY-MM-DD Hh:mm[:ss[.uuuuuu]][tz]DatefieldDate Format: YYYY-MM-DDTimefieldTime Format: hh:mm[:ss[.uuuuuu]]Common Keywords NULL: null is allowed (for example: null = True)default: null is allowed (example: default = "123")Primary_key: Set Primary KEY (example: Primary_key = True)db_column: Column Name (example: db_column = "Address", the default is the same as the variable name, use this keyword can be modified to the name you want)Db_index: IndexUnique: Unique indexunique_for_date: Date is unique indexUnique_for_month: Month is a unique indexUnqieu_for_day: Day is a unique indexAuto_now: Automatic Update Update (example: Auto_now = True)
obj = models. DjangoInfo.objects.filter (id=1).
Obj.password = 123
Obj.save () # only updates saved by the Save method, Auto_ Now it's working.
Auto_now_add: The first time you insert data, automatically add data, Auto_now_add and Auto_now generally used for time operations, such as record creation time and update time
Choices: Use unchanged data in memory to avoid cross-table operations
User_type_choices = (
1, "male"),
(2, "female"),
(3, "Simon")
)
user_type_id = models. Integerfield (choices=user_type_choices,default=1)
# The data deposited is the previous number, 1,2,3
Blank: Is null, used in Django admin