Django Model Field Reference list

  Django

Django Model Field Reference list

 

 

Field Default Widget Description
AutoField N/A An IntegerField that automatically increments according to available IDs.
BigIntegerField NumberInput A 64-bit integer, much like an IntegerField except that it is guaranteed to fit numbers from -9223372036854775808 to 9223372036854775807
BinaryField N/A A field to store raw binary data. It only supports bytes assignment. Be aware that this field has limited functionality.
BooleanField CheckboxInput A true/false field. If you need to accept null values then use NullBooleanField instead.
CharField TextInput A string field, for small- to large-sized strings. For large amounts of text, use TextField.CharField has one extra required argument: max_length. The maximum length (in characters) of the field.
DateField DateInput A date, represented in Python by a datetime.date instance. Has two extra, optional arguments: auto_now which automatically set the field to now every time the object is saved, and auto_now_add which automatically set the field to now when the object is first created.
DateTimeField DateTimeInput A date and time, represented in Python by a datetime.datetime instance. Takes the same extra arguments as DateField.
DecimalField TextInput A fixed-precision decimal number, represented in Python by a Decimalinstance. Has two required arguments: max_digits and decimal_places.
DurationField TextInput A field for storing periods of time – modeled in Python by timedelta.
EmailField TextInput CharField that uses EmailValidator to validate the input. max_length defaults to 254.
FileField ClearableFileInput A file upload field. For more information on FileField, see the next section.
FilePathField Select CharField whose choices are limited to the filenames in a certain directory on the filesystem.
FloatField NumberInput A floating-point number represented in Python by a float instance. Note when field.localize is False, the default widget is TextInput
ImageField ClearableFileInput Inherits all attributes and methods from FileField, but also validates that the uploaded object is a valid image. Additional height and width attributes. Requires the Pillow[70] library.
IntegerField NumberInput An integer. Values from -2147483648 to 2147483647 are safe in all databases supported by Django.
GenericIPAddressField TextInput An IPv4 or IPv6 address, in string format (e.g. 192.0.2.30 or 2a02:42fe::4).
NullBooleanField NullBooleanSelect Like a BooleanField, but allows NULL as one of the options.
PositiveIntegerField NumberInput An integer . Values from 0 to 2147483647 are safe in all databases supported by Django.
SlugField TextInput Slug is a newspaper term. A slug is a short label for something, containing only letters, numbers, underscores or hyphens.
SmallIntegerField NumberInput Like an IntegerField, but only allows values under a certain point. Values from -32768 to 32767 are safe in all databases supported by Django.
TextField Textarea A large text field. If you specify a max_length attribute, it will be reflected in the Textarea widget of the auto-generated form field.
TimeField TextInput A time, represented in Python by a datetime.time instance.
URLField URLInput CharField for a URL. Optional max_length argument.
UUIDField TextInput A field for storing universally unique identifiers. Uses Python’s UUID class
Spread the Code

Leave a Reply

avatar

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  Subscribe  
Notify of