Fixed #11381 -- `GeoManager` + `select_related` + nullable `ForeignKey` now works correctly. Thanks, bretthoerner for ticket and dgouldin for initial patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11123 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
735309341e
commit
fdcc0c774a
|
@ -225,7 +225,7 @@ class GeoQuery(sql.Query):
|
||||||
values.append(self.convert_values(value, field))
|
values.append(self.convert_values(value, field))
|
||||||
else:
|
else:
|
||||||
values.extend(row[index_start:])
|
values.extend(row[index_start:])
|
||||||
return values
|
return tuple(values)
|
||||||
|
|
||||||
def convert_values(self, value, field):
|
def convert_values(self, value, field):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -40,5 +40,5 @@ class Author(models.Model):
|
||||||
|
|
||||||
class Book(models.Model):
|
class Book(models.Model):
|
||||||
title = models.CharField(max_length=100)
|
title = models.CharField(max_length=100)
|
||||||
author = models.ForeignKey(Author, related_name='books')
|
author = models.ForeignKey(Author, related_name='books', null=True)
|
||||||
objects = models.GeoManager()
|
objects = models.GeoManager()
|
||||||
|
|
|
@ -257,6 +257,13 @@ class RelatedGeoModelTest(unittest.TestCase):
|
||||||
self.assertEqual(1, len(qs))
|
self.assertEqual(1, len(qs))
|
||||||
self.assertEqual(3, qs[0].num_books)
|
self.assertEqual(3, qs[0].num_books)
|
||||||
|
|
||||||
|
def test13_select_related_null_fk(self):
|
||||||
|
"Testing `select_related` on a nullable ForeignKey via `GeoManager`. See #11381."
|
||||||
|
no_author = Book.objects.create(title='Without Author')
|
||||||
|
b = Book.objects.select_related('author').get(title='Without Author')
|
||||||
|
# Should be `None`, and not a 'dummy' model.
|
||||||
|
self.assertEqual(None, b.author)
|
||||||
|
|
||||||
# TODO: Related tests for KML, GML, and distance lookups.
|
# TODO: Related tests for KML, GML, and distance lookups.
|
||||||
|
|
||||||
def suite():
|
def suite():
|
||||||
|
|
Loading…
Reference in New Issue