non_polymorphic() queryset member function added

This commit is contained in:
Bert Constantin
2010-10-23 12:20:23 +02:00
parent 19adbdaf2c
commit 8c3df56cb6
3 changed files with 21 additions and 7 deletions
+7
View File
@@ -42,6 +42,13 @@ class PolymorphicQuerySet(QuerySet):
new.polymorphic_disabled = self.polymorphic_disabled
return new
def non_polymorphic(self, *args, **kwargs):
"""switch off polymorphic behaviour for this query.
When the queryset is evaluated, only objects of the type of the
base class used for this query are returned."""
self.polymorphic_disabled = True
return self
def instance_of(self, *args):
"""Filter the queryset to only include the classes in args (and their subclasses).
Implementation in _translate_polymorphic_filter_defnition."""
+7
View File
@@ -289,6 +289,13 @@ __test__ = {"doctest": """
>>> o.get_real_instance()
<Model2C: id 3, field1 (CharField), field2 (CharField), field3 (CharField)>
# non_polymorphic()
>>> Model2A.objects.all().non_polymorphic()
[ <Model2A: id 1, field1 (CharField)>,
<Model2A: id 2, field1 (CharField)>,
<Model2A: id 3, field1 (CharField)>,
<Model2A: id 4, field1 (CharField)> ]
### test inheritance pointers & _base_managers