i found that even trying to access the relation (
the only special thing about my model is that i defined foo's primary key as BigIntegerField
On Tuesday, August 4, 2015 at 8:15:42 AM UTC+4:30, mohse...@gmail.com wrote:
-- i.e. foo.bars) will trigger the same error !!!the only special thing about my model is that i defined foo's primary key as BigIntegerField
On Tuesday, August 4, 2015 at 8:15:42 AM UTC+4:30, mohse...@gmail.com wrote:
Erik, as stated in documentation, 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/ , line 1253, in __get__models/fields/related.py"
through=self.field.rel.through,
File "/usr/local/lib/python2.7/dist-packages/django/db/ , line 862, in __init__models/fields/related.py"
source_field = through._meta.get_field(source_field_name )
File "/usr/local/lib/python2.7/dist-packages/django/db/ , line 554, in get_fieldmodels/options.py"
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:
>
> 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+unsubscribe@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/125f12da-02ff-4202-8ca8-4509e9d5154f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment