MCPcopy Index your code
hub / github.com/django-haystack/django-haystack / _new_instance

Method _new_instance

haystack/backends/__init__.py:268–279  ·  view source on GitHub ↗

This is called to create a new instance of this class when we need new Nodes (or subclasses) in the internal code in this class. Normally, it just shadows __init__(). However, subclasses with an __init__ signature that is not an extension of Node.__init__ might need

(cls, children=None, connector=None, negated=False)

Source from the content-addressed store, hash-verified

266 # We need this because of django.db.models.query_utils.Q. Q. __init__() is
267 # problematic, but it is a natural Node subclass in all other respects.
268 def _new_instance(cls, children=None, connector=None, negated=False):
269 """
270 This is called to create a new instance of this class when we need new
271 Nodes (or subclasses) in the internal code in this class. Normally, it
272 just shadows __init__(). However, subclasses with an __init__ signature
273 that is not an extension of Node.__init__ might need to implement this
274 method to allow a Node to create a new instance of them (if they have
275 any extra setting up to do).
276 """
277 obj = SearchNode(children, connector, negated)
278 obj.__class__ = cls
279 return obj
280
281 _new_instance = classmethod(_new_instance)
282

Callers 3

addMethod · 0.95
negateMethod · 0.95
start_subtreeMethod · 0.95

Calls 1

SearchNodeClass · 0.85

Tested by

no test coverage detected