0

I have one many to many field in my model.py

in that case i'm getting data as a queryset. But i want data as list. How to achieve that ?

Rika Das
  • 123
  • 1
  • 11
  • did you try `{{ rt.Developer }}` in the template? – yuv Jun 16 '21 at 10:27
  • Hey @yuv , yes i have tried that , in that case i getting hello.developer.None. here hellp is my app name and developer is the field name – Rika Das Jun 16 '21 at 10:32
  • sorry, i got wrong.. But I posted the answer.. Please check that out – yuv Jun 16 '21 at 10:38
  • Thanks @Yuv But if i want that m2m field while edit (django form) how to get that ? can yo please help me. i'm totally new to this django platform – Rika Das Jun 16 '21 at 10:45
  • Do you use Django ModelForm? If so then you can handle the post request method in the views.py file. Check if the form is valid and save. It will automatically save the model data in the database. – yuv Jun 16 '21 at 10:55
  • @yuv, yes i'm using django form. But not able to achieve that. I'll post another question regarding this . with the code you will better understand my problem – Rika Das Jun 16 '21 at 11:06
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/233840/discussion-between-rika-das-and-yuv). – Rika Das Jun 16 '21 at 11:48

2 Answers2

0

It is because there are more than one variable in Developer model. I think you are showing your data in a table data for that to work you should assign a str(self) function for the Developer model as it is mentioned below link:

django display content of a manytomanyfield

I hope it is clear.

tealy
  • 132
  • 1
  • 12
  • Hey i have updated my question. there i passed my data and in your code i'm not able to understand why login is required – Rika Das Jun 16 '21 at 10:24
0

This will work

{% for rt in JIRA %}
{% for dev in rt.Developer.all %}
<td>{{dev}} </td>
{% endfor %}
{% endfor %}
yuv
  • 499
  • 1
  • 7
  • 14