Fixed #12731. Fixed a bug with .raw() and inheritance. Thanks, Alex Gaynor.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12544 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
65b451ae3e
commit
c05de31d75
@ -1402,7 +1402,7 @@ class RawQuerySet(object):
|
|||||||
# Construct model instance and apply annotations
|
# Construct model instance and apply annotations
|
||||||
skip = set()
|
skip = set()
|
||||||
for field in self.model._meta.fields:
|
for field in self.model._meta.fields:
|
||||||
if field.name not in model_init_kwargs.keys():
|
if field.attname not in model_init_kwargs.keys():
|
||||||
skip.add(field.attname)
|
skip.add(field.attname)
|
||||||
|
|
||||||
if skip:
|
if skip:
|
||||||
|
@ -22,4 +22,7 @@ class Coffee(models.Model):
|
|||||||
brand = models.CharField(max_length=255, db_column="name")
|
brand = models.CharField(max_length=255, db_column="name")
|
||||||
|
|
||||||
class Reviewer(models.Model):
|
class Reviewer(models.Model):
|
||||||
reviewed = models.ManyToManyField(Book)
|
reviewed = models.ManyToManyField(Book)
|
||||||
|
|
||||||
|
class FriendlyAuthor(Author):
|
||||||
|
pass
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
from django.test import TestCase
|
from datetime import date
|
||||||
from datetime import datetime
|
|
||||||
from models import Author, Book, Coffee, Reviewer
|
|
||||||
from django.db.models.sql.query import InvalidQuery
|
from django.db.models.sql.query import InvalidQuery
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
from models import Author, Book, Coffee, Reviewer, FriendlyAuthor
|
||||||
|
|
||||||
|
|
||||||
class RawQueryTests(TestCase):
|
class RawQueryTests(TestCase):
|
||||||
|
|
||||||
@ -197,3 +200,13 @@ class RawQueryTests(TestCase):
|
|||||||
self.assertEquals(len(first_two), 2)
|
self.assertEquals(len(first_two), 2)
|
||||||
|
|
||||||
self.assertRaises(TypeError, lambda: Author.objects.raw(query)['test'])
|
self.assertRaises(TypeError, lambda: Author.objects.raw(query)['test'])
|
||||||
|
|
||||||
|
def test_inheritance(self):
|
||||||
|
# date is the end of the Cuban Missile Crisis, I have no idea when
|
||||||
|
# Wesley was bron
|
||||||
|
f = FriendlyAuthor.objects.create(first_name="Wesley", last_name="Chun",
|
||||||
|
dob=date(1962, 10, 28))
|
||||||
|
query = "SELECT * FROM raw_query_friendlyauthor"
|
||||||
|
self.assertEqual(
|
||||||
|
[o.pk for o in FriendlyAuthor.objects.raw(query)], [f.pk]
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user