django database connection type

Field Type

The field type which models django addition to the above usual models.CharField and models.IntegerField, there are many more types of

1, models.AutoField auto-increment = int (11)
  , if not, it generates a default name for the id column, if the custom to display an auto-increment, will be the primary key column primary_key = True.
2, models.CharField string field
  must max_length parameter
3, models.BooleanField boolean = tinyint (1)
  can not be empty, Blank = True
. 4, comma separated digital models.ComaSeparatedIntegerField = varchar
  inheritance CharField, parameters must max_lenght
5 , models.DateField date type date
  for the parameters, auto_now = True then each update will update this time; auto_now_add then just add first created, no longer change after the update.
6, models.DateTimeField date datetime type
  with parameters DateField
7, models.Decimal = decimal decimal type
  must be specified bit integer and decimal max_digits decimal_places
. 8, models.EmailField string type (regular expressions mailbox) = varchar
  string regular expression
9, models.FloatField Double float type =
10, shaping models.IntegerField
11, models.BigIntegerField long integer
  integer_field_ranges = {
    'SmallIntegerField': (- 32768,32767),
    'IntegerField': (- 2147483648,2147483647),
    'BigIntegerField': (- 9223372036854775808,9223372036854775807),
    'PositiveSmallIntegerField' :( 0, 32767),
    'PositiveIntegerField' :( 0,2147483647),
  }
12 is, models.IPAddressField string type (IP4 regular expressions)
13 is, models.GenericIPAddressField string type (IP4 and ip6 optional)
  parameters may be protocol: both, ipv4, ipv6
  verification, based on the setting error
14, models.NullBooleanField allow boolean empty
15, models.PositiveIntegerFiel positive Integer
16, models.PositiveSmallIntegerField n smallInteger
. 17, models.SlugField minus sign, underscore, letters, numbers,
18, models.SmallIntegerField digital
  There are fields in the database: tinyint, smallint The, int, BIGINT
. 19, models.TextField string LONGTEXT =
20 is, models.TimeField Time HH: the MM [: SS [.uuuuuu]]
21 is, models.URLField string, the regular expression address type
22, models.BinaryField binary
23, models.ImageField picture
24, models.FilePathField file

Field parameters

Corresponding field parameters are as follows:

1, null = True
  database whether the field can be null
2, blank = True
  if the allowable data is added django Admin is the null value
3, primary_key = False
  primary key, after AutoField set the primary key, it will replace the original self-energizing id column
4, auto_now and auto_now_add
  auto_now automatically create --- whether to add or modify, the current operation is time
  auto_now_add --- always automatically creates time it was created
. 5, choices
GENDER_CHOICE = (
(u'M ', u'Male '),
(u'F', u'Female '),
)
Gender = models.CharField (MAX_LENGTH = 2, = GENDER_CHOICE choices)
. 6, MAX_LENGTH
. 7, default default
8, the name of a field in verbose_name Admin
9, name | db_column field names in the database
10, unique = True allowed to repeat
11, db_index = True database index
12, editable = True in the Admin is editable
13, error_messages = None error
14, auto_created = False automatically create
15, help_text Help information Admin,
16, validators = []
. 17, to-Upload

mysql django CRUD operations:

    • All data rows obtained by the model manager objects all (), corresponding to the FROM SQL * in the SELECT
      A = User.objects.all ()

    • filter is equivalent to the SQL WHERE, filter the results set condition
      b = User.objects.filter (id = 1)

    • Obtaining a single object
      c = User.objects.get (id = 1)

    • Limit returned data corresponds to the LIMIT SQL 2 0 in the OFFSET;
      D = User.objects.order_by ( 'name') [0: 2]

    • Sorting Results
      e = User.objects.order_by ( "id")

    • The above method can be attached using
      f = User.objects.filter (name = "runoob "). Order_by ( "id")

Guess you like

Origin www.cnblogs.com/zhouzz2019/p/10983063.html