def add(self, data, *args, **kwargs): # WhereNode will convert params into strings, so we need to record # the type of the params as part of the value_annotation before calling # the super class if not isinstance(data, (list, tuple)): return super(HStoreWhereNode, self).add(data, *args, **kwargs) original_value = data[2] if isinstance(original_value, dict): len_children = len(self.children) if self.children else 0 value_annot = get_value_annotations(original_value) # We should be able to get the normal child node here, but it is not returned in Django 1.5 super(HStoreWhereNode, self).add(data, *args, **kwargs) # We also need to place the type annotation into self.children # It will either be the last item in the last child, or be the last child # We can tell which by comparing the lengths before and after calling the super method if len_children < len(self.children): child = self.children[-1] obj, lookup_type, _, value = child annotated_child = (obj, lookup_type, value_annot, value) self.children[-1] = annotated_child else: child = self.children[-1][-1] obj, lookup_type, _, value = child annotated_child = (obj, lookup_type, value_annot, value) self.children[-1][-1] = annotated_child else: return super(HStoreWhereNode, self).add(data, *args, **kwargs)
def __init__(self, lhs, rhs, *args, **kwargs): # We need to record the types of the rhs parameters before they are converted to strings if isinstance(rhs, dict): self.value_annot = get_value_annotations(rhs) super(HStoreLookupMixin, self).__init__(lhs, rhs)