From 2729187591ba7e39081e608ec87f7f7e90279009 Mon Sep 17 00:00:00 2001 From: Bert Constantin Date: Sat, 16 Jan 2010 18:03:25 +0100 Subject: [PATCH] manager: proxy all unknown methods --- poly/polymorphic.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/poly/polymorphic.py b/poly/polymorphic.py index 6fcd617..56696de 100644 --- a/poly/polymorphic.py +++ b/poly/polymorphic.py @@ -509,13 +509,17 @@ class PolymorphicManager(models.Manager): def get_query_set(self): return self.queryset_class(self.model) + # proxy all unknown method calls to the queryset + # so that its members are directly accessible from PolymorphicModel.objects. + # The advantage is that not yet known member functions of derived querysets will be proxied as well. + # But also execute all special functions (__) as usual. + def __getattr__(self, name): + if name.startswith('__'): return super(PolymorphicManager, self).__getattr__(self, name) + return getattr(self.get_query_set(), name) + def __unicode__(self): return self.__class__.__name__ + ' (PolymorphicManager) using ' + self.queryset_class.__name__ - # proxies to queryset - def instance_of(self, *args, **kwargs): return self.get_query_set().instance_of(*args, **kwargs) - def not_instance_of(self, *args, **kwargs): return self.get_query_set().not_instance_of(*args, **kwargs) - ################################################################################### ### PolymorphicQuerySet