Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
class JSONTextFieldFilter(Filter): | |
json_field_name = "" | |
choices = {} | |
def __init__(self, json_field_name=None, choices=None, **kwargs): | |
self.choices = choices if choices else {} | |
self.json_field_name = json_field_name if json_field_name else "" | |
super().__init__(**kwargs) | |
def modify_value(self, value): |
class defaultattr: | |
def __init__(self, expected_type): | |
self.expected_type = expected_type | |
def __getattr__(self, expected_type): | |
if isinstance(self.expected_type, type): | |
return self.expected_type() | |
return self.expected_type |
import copy | |
from collections import Mapping | |
from rest_framework import serializers | |
from rest_framework.fields import SkipField | |
from rest_framework.relations import PKOnlyObject | |
def dict_merge(dct, merge_dct): | |
""" Recursive dict merge. Inspired by :meth:``dict.update()``, instead of |
import functools | |
import sys | |
import re | |
from django.conf import settings | |
from django.db import connection | |
def shrink_select(sql): | |
return re.sub("^SELECT(.+)FROM", "SELECT .. FROM", sql) | |
def shrink_update(sql): |
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!