Refs #32380 -- Added test for distance lookups with F() expression.

Fixed in 5935a9aead.
This commit is contained in:
Mariusz Felisiak 2021-01-25 08:40:46 +01:00 committed by GitHub
parent 2b4b6c8af0
commit 84ad7f3404
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View File

@ -29,6 +29,7 @@ class AustraliaCity(NamedModel):
point = models.PointField() point = models.PointField()
radius = models.IntegerField(default=10000) radius = models.IntegerField(default=10000)
allowed_distance = models.FloatField(default=0.5) allowed_distance = models.FloatField(default=0.5)
ref_point = models.PointField(null=True)
class CensusZipcode(NamedModel): class CensusZipcode(NamedModel):

View File

@ -204,10 +204,12 @@ class DistanceTest(TestCase):
# With spheroid param # With spheroid param
if connection.features.supports_distance_geodetic: if connection.features.supports_distance_geodetic:
hobart = AustraliaCity.objects.get(name='Hobart') hobart = AustraliaCity.objects.get(name='Hobart')
qs = AustraliaCity.objects.filter( AustraliaCity.objects.update(ref_point=hobart.point)
point__distance_lte=(hobart.point, F('radius') * 70, 'spheroid'), for ref_point in [hobart.point, F('ref_point')]:
).order_by('name') qs = AustraliaCity.objects.filter(
self.assertEqual(self.get_names(qs), ['Canberra', 'Hobart', 'Melbourne']) point__distance_lte=(ref_point, F('radius') * 70, 'spheroid'),
).order_by('name')
self.assertEqual(self.get_names(qs), ['Canberra', 'Hobart', 'Melbourne'])
# With a complex geometry expression # With a complex geometry expression
self.assertFalse(SouthTexasCity.objects.filter(point__distance_gt=(Union('point', 'point'), 0))) self.assertFalse(SouthTexasCity.objects.filter(point__distance_gt=(Union('point', 'point'), 0)))