From: hernani Date: Wed, 19 May 2010 23:46:35 +0000 (+0000) Subject: One more 1.2 compatibility fix. X-Git-Tag: live~823 X-Git-Url: https://git.openstreetmap.org./osqa.git/commitdiff_plain/4cf907a4492224ac83151ce54a845f72363fc4a9 One more 1.2 compatibility fix. git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@308 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- diff --git a/forum/models/node.py b/forum/models/node.py index cf69233..4f6b6d1 100644 --- a/forum/models/node.py +++ b/forum/models/node.py @@ -78,25 +78,27 @@ class NodeMetaClass(BaseMetaClass): Node.add_to_class(name, property(parent)) +class NodeQuerySet(CachedQuerySet): + def get(self, *args, **kwargs): + node = super(NodeQuerySet, self).get(*args, **kwargs) + cls = NodeMetaClass.types.get(node.node_type, None) + + if cls and (node.__class__ is not cls): + return node.leaf + return node + + class NodeManager(CachedManager): use_for_related_fields = True def get_query_set(self): - qs = super(NodeManager, self).get_query_set() + qs = NodeQuerySet(self.model) if self.model is not Node: return qs.filter(node_type=self.model.get_type()) else: return qs - def get(self, *args, **kwargs): - node = super(NodeManager, self).get(*args, **kwargs) - cls = NodeMetaClass.types.get(node.node_type, None) - - if cls and node.__class__ is not cls: - return node.leaf - return node - def get_for_types(self, types, *args, **kwargs): kwargs['node_type__in'] = [t.get_type() for t in types] return self.get(*args, **kwargs)