Django models provide a variety of field types that you can use to define the structure of your database tables. Each field type corresponds to a different kind of data that you want to store, such as text, numbers, dates, or files.
Django fields are defined as class attributes inside a model class that inherits from models.Model.
Used to store short text values and requires max_length.
# CharField example for short text
from django.db import models
class Product(models.Model):
name = models.CharField(max_length=100)
Stores whole numbers such as price or quantity.
# IntegerField for numeric values
class Product(models.Model):
price = models.IntegerField()
Stores decimal numbers like ratings.
# FloatField for decimal values
class Product(models.Model):
rating = models.FloatField()
Stores date values.
# DateField for storing dates
class Event(models.Model):
date = models.DateField()
Stores True/False values.
# BooleanField for flags
class Product(models.Model):
is_active = models.BooleanField(default=True)
Stores long text without length restriction.
# TextField for long descriptions
class Product(models.Model):
description = models.TextField()
Validates and stores email addresses.
# EmailField with built-in validation
class Customer(models.Model):
email = models.EmailField()
Model Design Insight: Choose fields carefully based on data type and validation needs.
See how Django field constraints work in real-time.
is_active