(self, compiler, connection, **extra_context)
| 320 | super().__init__(*expressions, **extra) |
| 321 | |
| 322 | def as_postgresql(self, compiler, connection, **extra_context): |
| 323 | clone = self.copy() |
| 324 | function = None |
| 325 | expr2 = clone.source_expressions[1] |
| 326 | geography = self.source_is_geography() |
| 327 | if expr2.output_field.geography != geography: |
| 328 | if isinstance(expr2, Value): |
| 329 | expr2.output_field.geography = geography |
| 330 | else: |
| 331 | clone.source_expressions[1] = Cast( |
| 332 | expr2, |
| 333 | GeometryField(srid=expr2.output_field.srid, geography=geography), |
| 334 | ) |
| 335 | |
| 336 | if not geography and self.geo_field.geodetic(connection): |
| 337 | # Geometry fields with geodetic (lon/lat) coordinates need special |
| 338 | # distance functions. |
| 339 | if self.spheroid: |
| 340 | # DistanceSpheroid is more accurate and resource intensive than |
| 341 | # DistanceSphere. |
| 342 | function = connection.ops.spatial_function_name("DistanceSpheroid") |
| 343 | # Replace boolean param by the real spheroid of the base field |
| 344 | clone.source_expressions.append( |
| 345 | Value(self.geo_field.spheroid(connection)) |
| 346 | ) |
| 347 | else: |
| 348 | function = connection.ops.spatial_function_name("DistanceSphere") |
| 349 | return super(Distance, clone).as_sql( |
| 350 | compiler, connection, function=function, **extra_context |
| 351 | ) |
| 352 | |
| 353 | def as_sqlite(self, compiler, connection, **extra_context): |
| 354 | if self.geo_field.geodetic(connection): |
nothing calls this directly
no test coverage detected