non_polymorphic() queryset member function added
This commit is contained in:
@@ -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."""
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user