What are the field types?

Find out what each field category is for on the Model Builder.

When you're using the Model Builder tool, you will add fields to each of your models. For each field, you will see a list of field categories to choose from. 

Take a look below to find out more about each option to determine which category is right for your field. 

 

Screenshot_36

 

Big Integer Field: A 64-bit integer, much like an IntegerField except that it is guaranteed to fit numbers from -9223372036854775808 to 9223372036854775807.

 

Binary Field: A field to store raw binary data. It can be assigned bytes, bytearray, or memoryview.

 

Boolean Field: A true/false field

 

Char Field: A string field, for small-to-large sized strings. For large amounts of text, use TextField.

 

Date Field: A date, represented in Python by a datetime.date instance. 

 

Date Time Field: A date and time, represented in Python by a datetime.datetime instance. Takes the same extra arguments as DateField.

 

Decimal Field: A fixed-precision decimal number, represented in Python by a Decimal instance. It validates the input using DecimalValidator. 

 

Duration Field: A field for storing periods of time - modeled in Python by timedelta. When used on PostgreSQL, the data type used is an interval and on Oracle the data type is INTERVAL DAY(9) TO SECOND(6). Otherwise a bigint of microseconds is used.

 

Email Field: A CharField that checks that the value is a valid email address using EmailValidator.

 

Float Field: A floating-point number represented in Python by a float instance.

 

Integer Field: An integer. Values from -2147483648 to 2147483647 are safe in all databases supported by Django.

 

Generic IP Address Field: An IPv4 or IPv6 address, in string format (e.g. 192.0.2.30 or 2a02:42fe::4). 

 

Positive Integer Field: Like an IntegerField, but must be either positive or zero (0). Values from 0 to 2147483647 are safe in all databases supported by Django. The value 0 is accepted for backward compatibility reasons.

 

Positive Small Integer Field: Like a PositiveIntegerField, but only allows values under a certain (database-dependent) point. Values from 0 to 32767 are safe in all databases supported by Django.

 

Slug Field: Slug 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.

 

Small Integer Field: Like an IntegerField, but only allows values under a certain (database-dependent) point. Values from -32768 to 32767 are safe in all databases supported by Django.

 

Text Field: A large text field. Use this instead of the Character Field if your text is going to be long. 

 

Time Field: A time, represented in Python by a datetime.time instance. Accepts the same auto-population options as DateField.

 

URL Field: A CharField for a URL, validated by URLValidator.

 

UUID Field: A 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).

 

Foreign Key: A many-to-one relationship. Requires two positional arguments: the class to which the model is related and the on_delete option.
To create a recursive relationship – an object that has a many-to-one relationship with itself – use models.ForeignKey('self', on_delete=models.CASCADE).
If you need to create a relationship on a model that has not yet been defined, you can use the name of the model, rather than the model object itself.

 

One to One Field: A one-to-one relationship. Conceptually, this is similar to a ForeignKey with unique=True, but the “reverse” side of the relation will directly return a single object.
This is most useful as the primary key of a model which “extends” another model in some way; Multi-table inheritance is implemented by adding an implicit one-to-one relation from the child model to the parent model, for example.

 

Many to Many Field: A many-to-many relationship. Requires a positional argument: the class to which the model is related, which works exactly the same as it does for ForeignKey, including recursive and lazy relationships.