Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Field type of django models

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Django database field type:

1. Models.AutoField auto-increment column = int (11)

If not, a column named id will be generated by default, and if you want to display a custom self-incrementing column, you must set the given column to the primary key primary_key=True.

2. Models.CharField string field

Must have max_length parameter

3. Models.BooleanFiled Boolean type = tinyint (1)

Cannot be empty, blank=True

4. Models.ComaSeparatedIntegerField numbers separated by commas = varchar

Inherit CharField, so the max_length parameter is required

5. Models.DateField date type date

For the parameter, auto_now = True, this time is updated with each update, auto_now_add is only created and added for the first time, and subsequent updates are no longer changed.

6. Models.DateTimeField date type, datetime

The same parameters as DateField

7. Models.Decimal decimal type = decimal

You must specify integer max_digits and decimal decimal_places

8. Models.EmailField string type (regular expression mailbox) = varchar

Perform regular expressions on strings

9. Models.FloatField floating point type = double10, models.IntegerField × × × 11, models.BigIntegerField length × × integer_field_ranges = {'SmallIntegerField': (- 32768),' IntegerField': (- 2147483648, 2147483647), 'BigIntegerField': (- 9223372036854775808) 9223372036854775807),' PositiveSmallIntegerField': (0men32767), 'PositiveIntegerField': (0147483647),} 12, models.IPAddressField string type (ip4 regular expression)

13 、 models.GenericIPAddressField

Parameter protocal can be: both, IPV4, IPV6

When verifying, an error will be reported according to the setting

14. Models.NullBooleanField allows empty Boolean type 15, models.PositiveIntegerField positive Integer16, models.PositiveSmallIntegerField positive smallInteger17, models.SlugField minus sign, underscore, letter, number 18, models.SmallIntegerField number

The fields in the database are: tinyint, smallint, int, bigint

19. Models.TextField string = longtext20, models.TimeField time HH:MM [: ss [.uuuuuuu]] 21, models.URLField string, address regular expression 22, models.BinaryField binary

23. Models.ImageField pictures

24. Models.FilePathField file

Parameters for more fields:

1. Whether the fields in the null=True database can be empty 2, and whether null values 3 and primary_key = False primary keys are allowed when adding data to the Admin of blank=True django. After the primary key is set on AutoField, it will be automatically created instead of the original self-increasing id columns 4, auto_now and auto_now_add auto_now-- whether added or modified, is the time of the current operation. That is, the last update time auto_now_add is automatically created-always the time when it was created That is, creation time 5, choicesGENDER_CHOICE = ((upright max_length=2, upright Male'), (upright Founding, upright Female'),) gender = models.CharField (max_length=2 Choices = GENDER_CHOICE) 6, maximum length of max_length 7, default value of default 8, display name of fields in verbose_name Django Admin 9, name | Field names in db_column database 10, unique=True does not allow duplicates 11, db_index = True database index 12, whether editable=True is editable in Admin 13, error_messages=None error prompt 14, auto_created=False automatic creation 15, Help_text prompts help information 16, validators= [] 17, upload-to in Django Admin

Field type: https://docs.djangoproject.com/en/dev/ref/models/fields/

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report