Field Types & Field Options
Django provides many field types for different data: CharField, TextField, IntegerField, DateTimeField, BooleanField, and more. Each field accepts options like max_length, default, blank, null, unique, and choices that control validation and database behavior.
20 min•By Priygop Team•Updated 2026
Common Field Types
- CharField(max_length=N) — Short text (title, name)
- TextField() — Long text (content, description)
- IntegerField() — Whole numbers
- FloatField() / DecimalField() — Decimal numbers
- BooleanField() — True/False
- DateField() / DateTimeField() — Dates and timestamps
- EmailField() — Email with validation
- URLField() — URL with validation
- SlugField() — URL-friendly text (my-blog-post)
- ImageField() / FileField() — File uploads
- JSONField() — JSON data (PostgreSQL/SQLite)
Fields & Options
Fields & Options
# blog/models.py
# from django.db import models
# class Product(models.Model):
# # Text fields
# name = models.CharField(max_length=200)
# description = models.TextField(blank=True)
# sku = models.CharField(max_length=50, unique=True)
#
# # Number fields
# price = models.DecimalField(max_digits=10, decimal_places=2)
# stock = models.IntegerField(default=0)
#
# # Boolean
# is_active = models.BooleanField(default=True)
#
# # Date/Time
# created_at = models.DateTimeField(auto_now_add=True)
# updated_at = models.DateTimeField(auto_now=True)
#
# # Choices
# CATEGORY_CHOICES = [
# ('electronics', 'Electronics'),
# ('clothing', 'Clothing'),
# ('books', 'Books'),
# ]
# category = models.CharField(
# max_length=20,
# choices=CATEGORY_CHOICES,
# default='electronics'
# )
#
# # File upload
# image = models.ImageField(upload_to='products/', blank=True)
#
# # Field options:
# # null=True -> DB allows NULL
# # blank=True -> Form allows empty
# # default=val -> Default value
# # unique=True -> Must be unique in DB
# # db_index=True -> Create database indexTip
Tip
Use blank=True for form validation and null=True for database NULLs. For strings, prefer blank=True with default='' over null=True.
Diagram
Loading diagram…
QuerySets are LAZY — no DB hit until evaluated.
Common Mistake
Warning
Using null=True on CharField/TextField. Django stores empty strings for text fields. Use blank=True, default='' instead.
Practice Task
Note
(1) Add validators to a field. (2) Create a model with choices. (3) Add help_text for admin clarity.
Quick Quiz
Key Takeaways
- Django provides many field types for different data: CharField, TextField, IntegerField, DateTimeField, BooleanField, and more.
- CharField(max_length=N) — Short text (title, name)
- TextField() — Long text (content, description)
- IntegerField() — Whole numbers