django-database Common Types and keywords __ database

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.