code: def _clean_data(self, data):
          
          if isinstance(data, bytes):
              data = data.decode(errors='replace')
  
          if isinstance(data, list):
              return [self._clean_data(d) for d in data]
          if isinstance(data, dict):
              SENSITIVE_FIELDS = {'api', 'token', 'key', 'secret', 'password', 'signature'}
  
              data = dict(data)
              if self.sensitive_fields:
                  SENSITIVE_FIELDS = SENSITIVE_FIELDS | {field.lower() for field in self.sensitive_fields}
  
              for key, value in data.items():
                  try:
                      value = ast.literal_eval(value)
                  except (ValueError, SyntaxError):
                      pass
                  if isinstance(value, list) or isinstance(value, dict):
                      data[key] = self._clean_data(value)
                  if key.lower() in SENSITIVE_FIELDS:
                      data[key] = self.CLEANED_SUBSTITUTE
          return data
docs: Clean a dictionary of data of potentially sensitive info before
          sending to the database.
          Function based on the "_clean_credentials" function of django
          (https://github.com/django/django/blob/stable/1.11.x/django/contrib/auth/__init__.py#L50)
  
          Fields defined by django are by default cleaned with this function
  
          You can define your own sensitive fields in your view by defining a set
          eg: sensitive_fields = {'field1', 'field2'}