          # admin widgets - we just need to use a select widget of some kind.
          if db_field.choices:
              return self.formfield_for_choice_field(db_field, request, **kwargs)
  
          # ForeignKey or ManyToManyFields
          if isinstance(db_field, (models.ForeignKey, models.ManyToManyField)):
              # Combine the field kwargs with any options for formfield_overrides.
              # Make sure the passed in **kwargs override anything in
              # formfield_overrides because **kwargs is more specific, and should
              # always win.
              if db_field.__class__ in self.formfield_overrides:
 
</s> remove             elif isinstance(db_field, models.ManyToManyField):
 </s> add             elif db_field.many_to_many: </s> remove         if isinstance(f, ManyToManyField):
 </s> add         if f.many_to_many: </s> remove     # avoid a circular import
    from django.db.models.fields.related import ManyToManyField
 </s> add  </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         if (not field.null and not field.has_default() and
                not isinstance(field, models.ManyToManyField) and
 </s> add         if (not field.null and not field.has_default() and not field.many_to_many and
        # Foreign key or many-to-many fields
        if db_field.many_to_many or isinstance(db_field, models.ForeignKey):
          # admin widgets - we just need to use a select widget of some kind.
          if db_field.choices:
              return self.formfield_for_choice_field(db_field, request, **kwargs)
  
        # Foreign key or many-to-many fields
        if db_field.many_to_many or isinstance(db_field, models.ForeignKey):
        # Foreign key or many-to-many fields
        if db_field.many_to_many or isinstance(db_field, models.ForeignKey):
              # Combine the field kwargs with any options for formfield_overrides.
              # Make sure the passed in **kwargs override anything in
              # formfield_overrides because **kwargs is more specific, and should
              # always win.
              if db_field.__class__ in self.formfield_overrides:
keep keep keep keep replace 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