  
              # Get the correct formfield.
              if isinstance(db_field, models.ForeignKey):
                  formfield = self.formfield_for_foreignkey(db_field, request, **kwargs)
              elif isinstance(db_field, models.ManyToManyField):
                  formfield = self.formfield_for_manytomany(db_field, request, **kwargs)
  
              # For non-raw_id fields, wrap the widget with a wrapper that adds
              # extra HTML -- the "add other" interface -- to the end of the
              # rendered output. formfield can be None if it came from a
 
</s> remove         # ForeignKey or ManyToManyFields
        if isinstance(db_field, (models.ForeignKey, models.ManyToManyField)):
 </s> add         # Foreign key or many-to-many fields
        if db_field.many_to_many or isinstance(db_field, models.ForeignKey): </s> remove                 if (isinstance(field, models.ManyToManyField) and
                        not field.remote_field.through._meta.auto_created):
 </s> add                 if field.many_to_many and not field.remote_field.through._meta.auto_created: </s> remove     # avoid a circular import
    from django.db.models.fields.related import ManyToManyField
 </s> add  </s> remove         m2m = isinstance(field, related.ManyToManyField)
        return relation, model, direct, m2m
 </s> add         return relation, model, direct, bool(field.many_to_many)  # many_to_many can be None </s> remove         forbidden_field_types = (
            models.DateTimeField,
            models.ForeignKey,
            models.ManyToManyField
        )

 </s> add 
            elif db_field.many_to_many:
  
              # Get the correct formfield.
              if isinstance(db_field, models.ForeignKey):
                  formfield = self.formfield_for_foreignkey(db_field, request, **kwargs)
            elif db_field.many_to_many:
                  formfield = self.formfield_for_manytomany(db_field, request, **kwargs)
  
              # For non-raw_id fields, wrap the widget with a wrapper that adds
              # extra HTML -- the "add other" interface -- to the end of the
              # rendered output. formfield can be None if it came from a
keep keep keep keep replace keep keep keep keep keep
 Refs #24227 -- Replaced M2M isinstance checks by field.many_to_many

Thanks Markus Holtermann, Collin Anderson and Tim Graham for the reviews. 
django/contrib/admin/options.py