Field
The most important and only necessary part of a model is the database field it defines
Field Name Restrictions
1. The field name cannot be a pythohn reserved word, which will result in a Python syntax error
2. The field cannot contain more than one underscore, which conflicts with the Django query statement syntax
Types of database columns
Autofield refers to a integerfield that can be self-increasing based on the available IDs. Usually you don't have to use it directly, and if you don't specify a primary key, the system will automatically include such a primary key in your model.
Booleanfield A True/False (True/false) field.
Charfield A string field for small-to-medium-length strings
Note: Charfield has an additional required parameter: MaxLength, which is the maximum length (number of characters) of the field. This maximum length is mandatory at the database level and in Django validation.
Commaaseparatedintegerfield A comma-separated integer number field. As in Charfield, the MaxLength parameter is required.
Datefield Date field
Note: Optional parameters
1. The Auto_now object is automatically set to the current date when it is saved, that is, the modified date
2, the Auto_now_add object is created automatically set to the current time, that is, the creation date
Datetimefield Time Date field, additional options same as Datefield
Emailfield A charfield that can check if a value is a valid e-mail address. The MaxLength parameter is not accepted, and its maxlength is automatically set to 75.
filefield File Upload field, the parameter must be upload_to a local file system path, appended to your media_root settings, which determines the output of the Get_<fieldname>_url () auxiliary function
Filepathfield file name under a directory in the filesystem
Floatfield floating point number,
Note: Required Parameters
1. The maximum number of digits allowed in a max_digits number
2, decimal_places number of decimal digits
ImageField with Filefield to verify that the uploaded object is a valid picture
Note: Optional parameters
1, Height_field height
2, Width_field width
Integerfield Integer
Ipaddressfield An IP address, expressed in string format (for example: "24.124.1.30").
Nullbooleanfield is like a booleanfield, but it supports none/null
Phonenumberfield It is a charfield and checks whether the value is a valid American phone format, such as (XXX-XXX-XXXX)
Positiveintegerfield Positive integers
Slugfield inserts are the terminology of the newspaper industry. A block is a short label for a piece of content that can contain only letters, numbers, underscores, or hyphens, typically used in URLs
Smallintegerfield similar to Integerfield, but only allowed in a database-related range of values (usually 32,768 to +32,767)
TextField Text length of unlimited length
Timefield time and seconds are displayed. It accepts the same specified parameters as Datefield and Datetimefield
Urlfield fields that store URLs
Usstatefield U.S. state abbreviation, two letters
XMLField It's a TextField, just to check that the value is the legitimate XML that matches the specified schema. It has a required parameter: Schema_path, which is the physical path to the relax NG (http://www.relaxng.org/) schema required to verify the legitimacy of the field.
Django Data Model-database field type