Erik, as stated in documentation <https://docs.djangoproject.com/en/1.8/ref/models/relations/#direct-assignment>, what you said is equivalent to what i did and the error exists yet. to have more details, here is the stack trace:
Traceback (most recent call last): File "<console>", line 2, in <module> File "/home/user/Workspace/src/models.py", line 155, in create_from_dict obj.bars.clear() File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/related.py", line 1253, in __get__ through=self.field.rel.through, File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/related.py", line 862, in __init__ source_field = through._meta.get_field(source_field_name) File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 554, in get_field raise FieldDoesNotExist('%s has no field named %r' % (self.object_name, field_name)) FieldDoesNotExist: Foo_bars has no field named None On Monday, August 3, 2015 at 3:01:28 PM UTC+4:30, Erik Cederstrand wrote: > > > > Den 03/08/2015 kl. 08.50 skrev mohse...@gmail.com <javascript:>: > > > > Hello Django community. > > I have two Django models Foo and Bar that have a ManyToMany relation: > > > > Class Foo(models.model): > > > > ... > > > > bars = models.ManyToManyField('Bar', related_name='foos') > > somewhere in the code, i do direct assignment to replace the relation > with a new list: > > > > foo_object.bars = [bar_object_list] > > You can't do that, AFAIK. You need to do: > > foo_object.bars.clear() > foo_object.bars.add(*bar_object_list) > > > Erik -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/55016063-1c4d-4d3f-b201-acf3ddbdeec9%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.