Model Field Types
All model fields inherit from the baseField class and accept common parameters.
Base Field Class
Field
Base class for all field types.Human-readable name for the field. If not provided, Django will automatically create it from the field name.
The name of the field. In most cases, this is automatically set by Django.
If True, this field is the primary key for the model.
Maximum length for string-based fields. Required for CharField and its subclasses.
If True, this field must be unique throughout the table.
If True, the field is allowed to be blank in forms. Note this is different from null.
If True, Django will store empty values as NULL in the database.
If True, a database index will be created for this field.
default
The default value for the field. Can be a value or a callable object.
db_default
A database-computed default value (expression or literal). Requires database support.
If False, the field will not be displayed in the admin or any other ModelForm.
If False, the field will not be serialized when the model is passed to Django’s serializers.
Set this to the name of a DateField or DateTimeField to require that this field be unique for the value of the date field.
Like unique_for_date, but requires the field to be unique with respect to the month.
Like unique_for_date and unique_for_month, but for the year.
An iterable of 2-tuples to use as choices for this field. If provided, the default form widget will be a select box.
Extra “help” text to be displayed with the form widget.
The name of the database column to use for this field. If not provided, Django will use the field’s name.
A comment on the database column. Requires database support for comments.
The name of the database tablespace to use for this field’s index, if applicable.
A list of validators to run for this field.
A dictionary of error messages to override the default messages that the field will raise.
String Fields
CharField
A string field for small- to large-sized strings.The maximum length (in characters) of the field. Required.
The database collation name for the field.
django/db/models/fields/__init__.py:1204
TextField
A large text field.The database collation name for the field.
django/db/models/fields/__init__.py:2482
EmailField
A CharField that checks that the value is a valid email address.Maximum length defaults to 254 to comply with RFCs 3696 and 5321.
django/db/models/fields/__init__.py:1955
SlugField
A field for storing URL slugs (short labels containing only letters, numbers, underscores or hyphens).Maximum length of the slug.
Creates a database index by default.
If True, the field accepts Unicode letters in addition to ASCII letters.
django/db/models/fields/__init__.py:2445
URLField
A CharField for a URL, validated by URLValidator.Maximum length defaults to 200.
django/db/models/fields/__init__.py:2677
Numeric Fields
IntegerField
An integer field. Values from -2147483648 to 2147483647 are safe in all databases supported by Django. Reference:django/db/models/fields/__init__.py:2099
BigIntegerField
A 64-bit integer. Values from -9223372036854775808 to 9223372036854775807 are safe. Reference:django/db/models/fields/__init__.py:2199
SmallIntegerField
Like IntegerField, but only allows values under a certain (database-dependent) point. Reference:django/db/models/fields/__init__.py:2216
PositiveIntegerField
Like IntegerField, but must be either positive or zero (0). Values from 0 to 2147483647 are safe. Reference:django/db/models/fields/__init__.py:2415
PositiveBigIntegerField
Like PositiveIntegerField, but allows values from 0 to 9223372036854775807. Reference:django/db/models/fields/__init__.py:2400
PositiveSmallIntegerField
Like PositiveIntegerField, but only allows values under a certain (database-dependent) point. Reference:django/db/models/fields/__init__.py:2430
FloatField
A floating-point number represented in Python by a float instance. Reference:django/db/models/fields/__init__.py:2057
DecimalField
A fixed-precision decimal number, represented in Python by a Decimal instance.The maximum number of digits allowed in the number.
The number of decimal places to store with the number.
django/db/models/fields/__init__.py:1698
Boolean Fields
BooleanField
A true/false field. The default form widget is CheckboxInput, or NullBooleanSelect if null=True. Reference:django/db/models/fields/__init__.py:1158
Date and Time Fields
DateField
A date, represented in Python by a datetime.date instance.Automatically set the field to now every time the object is saved.
Automatically set the field to now when the object is first created.
django/db/models/fields/__init__.py:1422
DateTimeField
A date and time, represented in Python by a datetime.datetime instance.Automatically set the field to now every time the object is saved.
Automatically set the field to now when the object is first created.
django/db/models/fields/__init__.py:1557
TimeField
A time, represented in Python by a datetime.time instance.Automatically set the field to now every time the object is saved.
Automatically set the field to now when the object is first created.
django/db/models/fields/__init__.py:2559
DurationField
A field for storing periods of time, represented in Python by timedelta. Reference:django/db/models/fields/__init__.py:1894
Binary and Other Fields
BinaryField
A field to store raw binary data.Binary fields are not editable by default.
django/db/models/fields/__init__.py:2702
UUIDField
A field for storing universally unique identifiers. Uses Python’s UUID class. Reference:django/db/models/fields/__init__.py:2766
FilePathField
A CharField whose choices are limited to the filenames in a certain directory on the filesystem.The absolute filesystem path to a directory from which this FilePathField should get its choices.
A regular expression as a string that FilePathField will use to filter filenames.
If True, includes subdirectories of path.
If True, includes files in the specified location.
If True, includes folders in the specified location.
Maximum length of the path.
django/db/models/fields/__init__.py:1981
GenericIPAddressField
An IPv4 or IPv6 address, in string format (e.g. 192.0.2.30 or 2a02:42fe::4).Limits valid inputs to the specified protocol. Accepted values are ‘both’, ‘IPv4’, or ‘IPv6’.
If True, unpacks IPv4-mapped IPv6 addresses like ::ffff:192.0.2.1.
django/db/models/fields/__init__.py:2254
Auto Fields
AutoField
An IntegerField that automatically increments.Auto fields must be primary keys.
django/db/models/fields/__init__.py:2910
BigAutoField
A 64-bit integer that automatically increments. Reference:django/db/models/fields/__init__.py:2918
SmallAutoField
Like AutoField, but only allows values under a certain (database-dependent) limit. Reference:django/db/models/fields/__init__.py:2926