text: Model field reference¶
  This document contains all the API references of
  Field including the
  field options and field types Django offers. function as follows:
  def contact_default(): return {"email": "to1@example.com"} contact_info = JSONField("ContactInfo", default=contact_default)
  Note that
  lambdas cannot be used for field options like
  default
  because they cannot be serialized by migrations.
  See that documentation for other caveats..
  The
  unique_for_date error message key was
  FileField¶
  A file-upload field.
  Note
  The
  primary_key and
  unique arguments are not supported, and will
  raise a
  TypeError if used.
  Has two optional arguments:
  FileField.
  upload_to¶
  - Changed in Django 1.7:
  upload_towas required in older versions of Django.
  A local filesystem path that will be appended to your
  MEDIA_ROOTsetting to determine the value of the
  urlattribute.
  Deprecated since version 1.7: This field has been deprecated in favor of
  GenericIPAddressField..
  Field API reference¶
  - class
  Field¶
  Fieldis an abstract class that represents a database table column. Django uses fields to create the database table (
  db_type()), to map Python types to database (
  get_prep_value()) and vice-versa (
  to_python()), and to apply Lookup API reference (
  get_prep_lookup()). two methods:
  get_internal_type()¶
  Returns a string naming this field for backend specific purposes. By default, it returns the class name.
  See Emulating built-in field types for usage in custom fields.
  db_type(connection)¶
  Returns the database column data type)¶
  valueis the current value of the model’s attribute, and the method should return data in a format that has been prepared for use as a parameter in a query.
  See Converting Python objects to query values for usage.
  get_db_prep_value(value, connection, prepared=False)¶
  Converts
  valueto a backend-specific value. By default it returns
  valueif
  prepared=Trueand
  get_prep_value()if is
  False.
  See Converting query values to database values for usage.
  When loading data,
  to_python()is used:
  to_python(value)¶
  Converts a value as returned by the database (or a serializer) to a Python object. It is the reverse of
  get_prep_value().
  The default implementation returns
  value, which is the common case when the database backend already returns the correct Python type.
  See Converting database values to Python objects for usage.
  When saving,
  pre_save()and
  get_db_prep_save()are used:
  get_db_prep_save(value, connection)¶
  Same as the
  get_db_prep_value(), but called when the field value must be saved to the database. By default returns
  get_db_prep_value().
  pre_save(model_instance, add.
  Besides saving to the database, the field also needs to know how to serialize its value (inverse of
  to_python()):
  value_to_string(obj)¶
  Converts
  objto a string. Used to serialize the value of the field.
  See Converting field data for serialization for usage.
  When a lookup is used on a field, the value may need to be “prepared”. Django exposes two methods for this:
  get_prep_lookup(lookup_type, value)¶
  Prepares
  valueto the database prior to be used in a lookup. The
  lookup_typew".New in Django 1.7.
  If you are using Custom lookups the
  lookup_typecan be any
  lookup_nameregistered in the field.
  See Preparing values for use in database lookups for usage.
  get_db_prep_lookup(lookup_type, value, connection, prepared=False)¶
  Similar to
  get_db_prep_value(), but for performing a lookup.
  As with
  get_db_prep_value(), the specific connection that will be used for the query is passed as
  connection. In addition,
  prepareddescribes whether the value has already been prepared with
  get_prep_lookup().
  When using
  model forms, the
  Fieldneeds to know which form field it should be represented by:
  formfield(form_class=None, choices_form_class=None, **kwargs)¶
  Returns the default
  django.forms.Fieldof this field for
  ModelForm.
  By default, if both
  form_classand
  choices_form_classare
  None, it uses
  CharField; if
  choices_form_classis given, it returns
  TypedChoiceField.
  See Specifying the form field for a model field for usage.
  deconstruct()¶
  - New in Django 1.7..