Skip to main content

DistanceField

Wrapper for Distance values.

Attributes

AttributeTypeDescription
geo_fieldmodels.FieldThe 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

NameTypeDescription
geo_fielddjango.contrib.gis.db.models.fields.FieldThe 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

NameTypeDescription
valueanyThe value to be prepared for a database query, typically a Distance object or a numeric type.

Returns

TypeDescription
`Distancefloat

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

NameTypeDescription
valueanyThe value to be converted for the database.
connectionDatabaseConnectionThe current database connection object used to determine unit attributes.
preparedboolean = FalseWhether the value has already been passed through get_prep_value.

Returns

TypeDescription
`floatany`

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

NameTypeDescription
value`floatnull`
expression[Expression](../../../../../../db/models/expressions/expression.md?sid=django_db_models_expressions_expression)The query expression that produced the value.
connectionDatabaseConnectionThe current database connection used to resolve distance unit attributes.

Returns

TypeDescription
`Distancefloat

get_internal_type()

@classmethod
def get_internal_type() - > string

Returns the internal name of the field type for Django's model introspection.

Returns

TypeDescription
stringThe string identifier "DistanceField" used by the framework.