  
          self.assertIsInvalid(
              ValidationTestModelAdmin, ValidationTestModel,
              ("The value of 'prepopulated_fields' refers to 'users', which must not be "
               "a DateTimeField, ForeignKey or ManyToManyField."),
              'admin.E028')
  
      def test_valid_case(self):
          class ValidationTestModelAdmin(ModelAdmin):
              prepopulated_fields = {"slug": ('name',)}
 
</s> remove             "The value of 'raw_id_fields[0]' must be a ForeignKey or ManyToManyField.",
 </s> add             "The value of 'raw_id_fields[0]' must be a foreign key or a many-to-many field.", </s> remove             "The value of 'filter_horizontal[0]' must be a ManyToManyField.",
 </s> add             "The value of 'filter_horizontal[0]' must be a many-to-many field.", </s> remove             "The value of 'filter_vertical[0]' must be a ManyToManyField.",
 </s> add             "The value of 'filter_vertical[0]' must be a many-to-many field.", </s> remove             "The value of 'list_display[0]' must not be a ManyToManyField.",
 </s> add             "The value of 'list_display[0]' must not be a many-to-many field.", </s> remove                         "ForeignKey or ManyToManyField." % (label, field_name),
 </s> add                         "a foreign key, or a many-to-many field." % (label, field_name),
             "a DateTimeField, a foreign key, or a many-to-many field."),
  
          self.assertIsInvalid(
              ValidationTestModelAdmin, ValidationTestModel,
              ("The value of 'prepopulated_fields' refers to 'users', which must not be "
             "a DateTimeField, a foreign key, or a many-to-many field."),
              'admin.E028')
  
      def test_valid_case(self):
          class ValidationTestModelAdmin(ModelAdmin):
              prepopulated_fields = {"slug": ('name',)}
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. 
tests/modeladmin/tests.py