• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: How to define ManyToManyField in Django for tests

Resolved: How to define ManyToManyField in Django for tests

0
By Isaac Tonny on 16/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

To test my serializers in django rest framework I use Model 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 define ManyToMany 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!

django django-rest-framework serialization
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: How can I modify formData before sending it?

01/04/2023

Resolved: How to efficient create SimpleITK image?

01/04/2023

Resolved: How can I write CSS selector(s) that apply to table rows for all td elements on that row after a td with a certain class?

01/04/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.