Vladimir Mihailenco avatar Vladimir Mihailenco committed 73673e3

Support for proxy models

Comments (0)

Files changed (2)

djangotoolbox/db/basecompiler.py

             db_table = self.query.model._meta.db_table
             fields = [f for f in fields if db_table in only_load and
                       f.column in only_load[db_table]]
+
+        query_model = self.query.model
+        if query_model._meta.proxy:
+            query_model = query_model._meta.proxy_for_model
+
         for field in fields:
-            if field.model._meta != self.query.model._meta:
+            if field.model._meta != query_model._meta:
                 raise DatabaseError('Multi-table inheritance is not supported '
                                     'by non-relational DBs.')
         return fields

djangotoolbox/tests.py

 from django.db import models, connections
 from django.db.models import Q
 from django.test import TestCase
+from django.db.utils import DatabaseError
 
 class ListModel(models.Model):
     floating_point = models.FloatField()
         self.assertEquals([entity.names for entity in
             ListModel.objects.exclude(Q(names__lt='Sakura') | Q(names__gte='Sasuke'))],
                 [['Kakashi', 'Naruto', 'Sasuke', 'Sakura'], ])
+
+class BaseModel(models.Model):
+    pass
+
+class ExtendedModel(BaseModel):
+    name = models.CharField(max_length=20)
+
+class BaseModelProxy(BaseModel):
+    class Meta:
+        proxy = True
+
+class ExtendedModelProxy(ExtendedModel):
+    class Meta:
+        proxy = True
+
+class ProxyTest(TestCase):
+    def test_proxy(self):
+        list(BaseModelProxy.objects.all())
+
+    def test_proxy_with_inheritance(self):
+        try:
+            list(ExtendedModelProxy.objects.all())
+        except DatabaseError:
+            pass
+        else:
+            self.fail()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.