Sunday, 12 May 2013

Django - Models.Field Blank & Null

Blank
* django: not required field on forms & db
* db: store as ''
* data type: Text/Char fields (Empty string will be stored as '')
text_field = models.CharField(max_length=50, blank=True)

Null
* django: not required field on db only
* db: store as NULL
* data type: Non-string fields (Integers, Booleans and Dates)
date_field = models.DateField(blank=True, null=True)

Foreignkey
user = models.ForeignKey(User, blank=True, null=True)

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

No comments :

Post a Comment