Open In App

Django model data types and fields list

Last Updated : 17 May, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Django models represent the structure of your database tables, and fields are the core components of those models. Fields define the type of data each database column can hold and how it should behave. This artcle covers all major Django model field types and their usage.

Defining Fields in a Model

Each field in a Django model is specified as a class attribute, and its type is determined by using a specific Django field class like CharField, IntegerField, etc. Avoid using reserved names like save, delete, or clean as field names to prevent conflicts with Django’s model API. Example:

Python
from django.db import models

class Musician(models.Model):
    first_name = models.CharField(max_length=200)
    last_name = models.CharField(max_length=200)
    instrument = models.CharField(max_length=200)

class Album(models.Model):
    artist = models.ForeignKey(Musician, on_delete=models.CASCADE)  # Links each album to a musician
    name = models.CharField(max_length=100)                         # Album name
    release_date = models.DateField()                               # Release date of the album
    num_stars = models.IntegerField()                               # Rating (e.g., out of 5)

Explanation of fields used in the above example:

  • CharField is used for short text like names or instruments.
  • IntegerField stores numbers (e.g., star ratings).
  • DateField holds date values.
  • ForeignKey establishes a relationship between two models (Album- Musician).

Role of Model Fields

Fields define the data type for each model attribute. Built-in validation ensures you can’t store the wrong type (e.g., text in an IntegerField).

Each Django field class helps Django determine:

  • The database column type (e.g., INTEGER, VARCHAR, TEXT)
  • The default HTML form widget (e.g., <input type="text">, <select>, etc.)
  • The built-in validation rules for that field

Django supports many built-in field types which can be used to save any type of data from number to entire HTML file too. Here is a list of all Field types used in Django.  

Common Field Types in Django

Field NameDescription
AutoFieldIt is an IntegerField that automatically increments.
BigAutoFieldIt is a 64-bit integer, much like an AutoField except that it is guaranteed to fit numbers from 1 to 9223372036854775807.
BigIntegerFieldIt is a 64-bit integer, much like an IntegerField except that it is guaranteed to fit numbers from -9223372036854775808 to 9223372036854775807.
BinaryFieldA field to store raw binary data. 
BooleanFieldA true/false field. 
The default form widget for this field is a CheckboxInput.
CharFieldA field to store text-based values.
DateFieldA date, represented in Python by a datetime.date instance
DateTimeFieldIt is used for date and time, represented in Python by a datetime.datetime instance.
DecimalFieldIt is a fixed-precision decimal number, represented in Python by a Decimal instance.
DurationFieldA field for storing periods of time.
EmailFieldIt is a CharField that checks that the value is a valid email address.
FileFieldIt is a file-upload field.
FloatFieldIt is a floating-point number represented in Python by a float instance.
ImageFieldIt inherits all attributes and methods from FileField, but also validates that the uploaded object is a valid image.
IntegerFieldIt is an integer field. Values from -2147483648 to 2147483647 are safe in all databases supported by Django.
GenericIPAddressFieldAn IPv4 or IPv6 address, in string format (e.g. 192.0.2.30 or 2a02:42fe::4).
NullBooleanFieldLike a BooleanField, but allows NULL as one of the options.
PositiveIntegerFieldLike an IntegerField, but must be either positive or zero (0).
PositiveSmallIntegerFieldLike a PositiveIntegerField, but only allows values under a certain (database-dependent) point.
SlugFieldSlug is a newspaper term. A slug is a short label for something, containing only letters, numbers, underscores or hyphens. They’re generally used in URLs.
SmallIntegerFieldIt is like an IntegerField, but only allows values under a certain (database-dependent) point.
TextFieldA large text field. The default form widget for this field is a Textarea.
TimeFieldA time, represented in Python by a datetime.time instance.
URLFieldA CharField for a URL, validated by URLValidator.
UUIDFieldA field for storing universally unique identifiers. Uses Python’s UUID class. When used on PostgreSQL, this stores in a uuid datatype, otherwise in a char(32).

Relationship Fields

These fields define how models relate to each other.

Field NameDescription
ForeignKey

Defines a many-to-one relationship. Requires a target model and an on_delete behavior.

ManyToManyField

Defines a many-to-many relationship. Accepts a target model and supports intermediate tables.

OneToOneFieldDefines a one-to-one relationship. Similar to ForeignKey with unique=True.

Also read:


Next Article
Practice Tags :

Similar Reads