docs: def make_dynamic_fields(pattern_module, dynamic_field_patterns, attrs):
      """Add some Salesforce fields from a pattern_module models.py
  
      Parameters:
          pattern_module:  Module where to search additional fields settings.
             It is an imported module created by introspection (inspectdb),
             usually named `models_template.py`. (You will probably not add it
             to version control for you because the diffs are frequent and huge.)
          dynamic_field_patterns:  List of regular expression for Salesforce
              field names that should be included automatically into the model.
          attrs:  Input/Output dictionary of model attributes. (no need to
              worry, added automatically)
  
      The patterns are applied sequentionally.
      If the pattern starts with "-" then the matched names are excluded.
      The search stops after the first match.
      A normal field that exists directly in a class is never rewritten
      by a dynamic field..
      All ForeingKey fields should be created explicitely. (For now to
      prevent possible issues and also for better readibility of the
      model. The automatic "dynamic" fields are intended especially for
      "maybe can be useful" fields and will work with ForeignKey in simple
      cases, e.g. without Proxy models etc. Works good for me.)
  
      This is useful for development: Many fields or all fields can be
      easily accessed by the model without a huge code. Finally
      all wildcard fields except the explicit names can be removed when
      the development is ready or .
      If you create migrations, you probably want to disable "dynamic_field_patterns"
      by setting them empty.
  
      Example:
          Meta:
              db_table = 'Contact'
              dynamic_patterns = exported.models, ['Last', '.*Date$']
      """
      # pylint:disable=invalid-name,too-many-branches,too-many-locals
      import re
      attr_meta = attrs['Meta']
      db_table = getattr(attr_meta, 'db_table', None)
      if not db_table:
          raise RuntimeError('The "db_table" must be set in Meta if "dynamic_field_patterns" is used.')
      is_custom_model = getattr(attr_meta, 'custom', False)
  
      patterns = []
      for pat in dynamic_field_patterns:
          enabled = True
          if pat.startswith('-'):
              enabled = False
              pat = pat[1:]
          patterns.append((enabled, re.compile(r'^(?:{})$'.format(pat), re.I)))
  
      used_columns = []
      for name, attr in attrs.items():
          if isinstance(attr, SfField):
              field = attr
              if field.sf_custom is None and is_custom_model:
                  field.sf_custom = True
              if not field.name:
                  field.name = name
              attname, column = field.get_attname_column()  # pylint:disable=unused-variable
              used_columns.append(column)
  
      if not pattern_module:
          raise RuntimeError("a pattern_module is required for dynamic fields.")
      for name, obj in vars(pattern_module).items():
          if not name.startswith('_') and isclass(obj) and issubclass(obj, ModelTemplate):
              default_table = obj.__name__
              if getattr(getattr(obj, 'Meta', None), 'db_table', default_table) == db_table:
                  cls = obj
                  break
      else:
          # not found db_table model, but decide between warning or exception
          if any(not x.startswith('__') for x in dir(pattern_module)):
              raise RuntimeError("No Model for table '%s' found in the module '%s'"
                                 % (db_table, pattern_module.__name__))
          warnings.warn("The module '%s' is empty. (It is OK if you are "
                        "rewriting new Models by pipe from inspectdb command.)"
                        % pattern_module.__name__)
          return
      lazy_fields = [(name, obj) for name, obj in vars(cls).items()
                     if isinstance(obj, LazyField) and issubclass(obj.klass, SfField)
                     ]
      for name, obj in sorted(lazy_fields, key=lambda name_obj: name_obj[1].counter):
          for enabled, pat in patterns:
              if pat.match(name):
                  break
          else:
              enabled = False
          if enabled:
              if issubclass(obj.klass, ForeignKey):
                  to = obj.kw['to']
                  if isclass(to) and issubclass(to, ModelTemplate):
                      obj.kw['to'] = to.__name__
              field = obj.create()
              attrs[name] = field
      assert pattern_module