Question:
To test my serializers in django rest framework I useModel Name.objects.create
method to create fields. But I can’t create ManyToManyField.Guess, firstly I need to create objects for first model and for second model otherwise ManyToManyField bound can’t be created. But still can’t define ManyToManyField for test with create method.
Please help me to realize how it should work correctly. I’ve red django documentation, but haven’t got how to solve my issue. Here is my code example:
models.py
test.py
readers
is None
, how to define self.user
?Thank you in advance.
Answer:
I think the command is correct. You can defineManyToMany
using set and modify using add
, remove
.
You can also use just ids of them like the following.If you have better answer, please add a comment about this, thank you!