Ok, so I am trying verify in my unittest that a certain field is a ManyToManyField object. Here is the original class, followed by the relevant unit testing code:
class Course(models.Model):
name = models.CharField(max_length=150)
studyunits = models.ManyToManyField(StudyUnit)
class CourseManyToManyTest(VocabTestCase):
fixtures = ['m2mtest.json']
def setUp(self):
self.course = Course.objects.create(name="Course2")
self.studyunit1 = StudyUnit.objects.all()[0]
self.studyunit2 = StudyUnit.objects.all()[1]
def testStudyUnitsAddDelete(self):
self.assertIsInstance(self.course.studyunits, models.ManyToManyField)
That test fails with the following error:
self.assertIsInstance(self.course.studyunits, models.ManyToManyField)
AssertionError: <django.db.models.fields.related.ManyRelatedManager object at 0x102853690> is not an instance of <class 'django.db.models.fields.related.ManyToManyField'>
I know it seems stupid to verify this, but I found this bug in trying to extend the ManyToManyField, and now I am curious why the object's class changes. Seems a bit too magical, what is the explanation?