berinhard / model_mommy

No longer maintained, please migrate to model_bakery
http://model-bakery.readthedocs.org/
Other
903 stars 141 forks source link

ManyRelatedManager has no attribute 'add' #79

Closed dmwyatt closed 11 years ago

dmwyatt commented 11 years ago

When a ManyToMany relation uses 'through', you cannot add an object with .add.

See http://stackoverflow.com/questions/8095813/attributeerror-manyrelatedmanager-object-has-no-attribute-add-i-do-like-in

When you attempt to do:

mommy.make(Employee)

When Employee has a field like:

references = models.ManyToManyField(Person, through='References')

model_mommy throws the following traceback:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/dustin/.virtualenvs/lalo-django/local/lib/python2.7/site-packages/model_mommy/mommy.py", line 52, in make
    return mommy.make(**attrs)
  File "/home/dustin/.virtualenvs/lalo-django/local/lib/python2.7/site-packages/model_mommy/mommy.py", line 210, in make
    return self._make(commit=True, **attrs)
  File "/home/dustin/.virtualenvs/lalo-django/local/lib/python2.7/site-packages/model_mommy/mommy.py", line 248, in _make
    return self.instance(model_attrs, _commit=commit)
  File "/home/dustin/.virtualenvs/lalo-django/local/lib/python2.7/site-packages/model_mommy/mommy.py", line 270, in instance
    m2m_relation.add(model_instance)
AttributeError: 'ManyRelatedManager' object has no attribute 'add'
dmwyatt commented 11 years ago

sorry, just noticed the other issue on this.