Loading docs/howto/custom-model-fields.txt +7 −4 Original line number Diff line number Diff line Loading @@ -458,11 +458,14 @@ For example:: else: return 'timestamp' The :meth:`.db_type` method is only called by Django when the framework The :meth:`.db_type` method is called by Django when the framework constructs the ``CREATE TABLE`` statements for your application -- that is, when you first create your tables. It's not called at any other time, so it can afford to execute slightly complex code, such as the ``connection.settings_dict`` check in the above example. when you first create your tables. It is also called when constructing a ``WHERE`` clause that includes the model field -- that is, when you retrieve data using QuerySet methods like ``get()``, ``filter()``, and ``exclude()`` and have the model field as an argument. It's not called at any other time, so it can afford to execute slightly complex code, such as the ``connection.settings_dict`` check in the above example. Some database column types accept parameters, such as ``CHAR(25)``, where the parameter ``25`` represents the maximum column length. In cases like these, Loading Loading
docs/howto/custom-model-fields.txt +7 −4 Original line number Diff line number Diff line Loading @@ -458,11 +458,14 @@ For example:: else: return 'timestamp' The :meth:`.db_type` method is only called by Django when the framework The :meth:`.db_type` method is called by Django when the framework constructs the ``CREATE TABLE`` statements for your application -- that is, when you first create your tables. It's not called at any other time, so it can afford to execute slightly complex code, such as the ``connection.settings_dict`` check in the above example. when you first create your tables. It is also called when constructing a ``WHERE`` clause that includes the model field -- that is, when you retrieve data using QuerySet methods like ``get()``, ``filter()``, and ``exclude()`` and have the model field as an argument. It's not called at any other time, so it can afford to execute slightly complex code, such as the ``connection.settings_dict`` check in the above example. Some database column types accept parameters, such as ``CHAR(25)``, where the parameter ``25`` represents the maximum column length. In cases like these, Loading