Ticket #12731: django-raw-inheritance.diff

File django-raw-inheritance.diff, 2.1 KB (added by Alex Gaynor, 15 years ago)
  • django/db/models/query.py

    diff --git a/django/db/models/query.py b/django/db/models/query.py
    index 7492039..6f66c3e 100644
    a b class RawQuerySet(object):  
    14021402        # Construct model instance and apply annotations
    14031403        skip = set()
    14041404        for field in self.model._meta.fields:
    1405             if field.name not in model_init_kwargs.keys():
     1405            if field.attname not in model_init_kwargs.keys():
    14061406                skip.add(field.attname)
    14071407
    14081408        if skip:
  • tests/modeltests/raw_query/models.py

    diff --git a/tests/modeltests/raw_query/models.py b/tests/modeltests/raw_query/models.py
    index fb5503d..6188d58 100644
    a b class Coffee(models.Model):  
    2222    brand = models.CharField(max_length=255, db_column="name")
    2323
    2424class Reviewer(models.Model):
    25     reviewed = models.ManyToManyField(Book)
    26  No newline at end of file
     25    reviewed = models.ManyToManyField(Book)
     26
     27class FriendlyAuthor(Author):
     28    pass
  • tests/modeltests/raw_query/tests.py

    diff --git a/tests/modeltests/raw_query/tests.py b/tests/modeltests/raw_query/tests.py
    index ceed674..38b784d 100644
    a b  
    1 from django.test import TestCase
    2 from datetime import datetime
    3 from models import Author, Book, Coffee, Reviewer
     1from datetime import date
     2
    43from django.db.models.sql.query import InvalidQuery
     4from django.test import TestCase
     5
     6from models import Author, Book, Coffee, Reviewer, FriendlyAuthor
     7
    58
    69class RawQueryTests(TestCase):
    710
    class RawQueryTests(TestCase):  
    197200        self.assertEquals(len(first_two), 2)
    198201
    199202        self.assertRaises(TypeError, lambda: Author.objects.raw(query)['test'])
     203   
     204    def test_inheritance(self):
     205        # date is the end of the Cuban Missile Crisis, I have no idea when
     206        # Wesley was bron
     207        f = FriendlyAuthor.objects.create(first_name="Wesley", last_name="Chun",
     208            dob=date(1962, 10, 28))
     209        query = "SELECT * FROM raw_query_friendlyauthor"
     210        self.assertEqual(
     211            [o.pk for o in FriendlyAuthor.objects.raw(query)], [f.pk]
     212        )
Back to Top