DistanceField
Wrapper for Distance values.
Attributes
| Attribute | Type | Description |
|---|---|---|
| geo_field | models.Field | The geographic field associated with this distance calculation, used to determine the appropriate unit attributes from the database connection. |
Constructor
Signature
def DistanceField(
geo_field: django.contrib.gis.db.models.fields.Field
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| geo_field | django.contrib.gis.db.models.fields.Field | The geographic field associated with this distance measurement. |
Methods
get_prep_value()
@classmethod
def get_prep_value(
value: any
) - > Distance|float|null
Prepares the value for use in a query by ensuring Distance objects are handled correctly before being passed to the database driver.
Parameters
| Name | Type | Description |
|---|---|---|
| value | any | The value to be prepared for a database query, typically a Distance object or a numeric type. |
Returns
| Type | Description |
|---|---|
| `Distance | float |
get_db_prep_value()
@classmethod
def get_db_prep_value(
value: any,
connection: DatabaseConnection,
prepared: boolean = False
) - > float|any
Converts a Distance object into a raw database value using the unit attribute appropriate for the associated geographic field.
Parameters
| Name | Type | Description |
|---|---|---|
| value | any | The value to be converted for the database. |
| connection | DatabaseConnection | The current database connection object used to determine unit attributes. |
| prepared | boolean = False | Whether the value has already been passed through get_prep_value. |
Returns
| Type | Description |
|---|---|
| `float | any` |
from_db_value()
@classmethod
def from_db_value(
value: float|null,
expression: [Expression](../../../../../../db/models/expressions/expression.md?sid=django_db_models_expressions_expression),
connection: DatabaseConnection
) - > Distance|float|null
Converts the raw database numeric value back into a Distance object using the units defined by the database backend.
Parameters
| Name | Type | Description |
|---|---|---|
| value | `float | null` |
| expression | [Expression](../../../../../../db/models/expressions/expression.md?sid=django_db_models_expressions_expression) | The query expression that produced the value. |
| connection | DatabaseConnection | The current database connection used to resolve distance unit attributes. |
Returns
| Type | Description |
|---|---|
| `Distance | float |
get_internal_type()
@classmethod
def get_internal_type() - > string
Returns the internal name of the field type for Django's model introspection.
Returns
| Type | Description |
|---|---|
string | The string identifier "DistanceField" used by the framework. |