DJANGO – 24 LINKING TABLES & MULTI-CHOICE FIELD

Spread the love

1. Add ManyToManyField() to models.py them migrate to the database

[python]
operating_system = models.ManyToManyField(Operating_system, blank=True)

[/python]

2. In views.py, use the following to save ManyToManyField objects

[python]
form.save_m2m()
[/python]

3. Use the following to display the content of ManyToManyField in the template

[python]
{{instance.operating_system.all}}
[/python]


Spread the love

About the author

arbadjie

Hi, I'm Abdourahman Badjie, an aspiring developer with obsession for anything coding and networking. This blog is dedicated to helping people learn to develop web applications using django framework.

View all posts

4 Comments

  • Hey trying to do the same, but the form keeps throwing not a valid value error when I submit.
    How did you do it on your html template?

  • Hello, I am confused how you are able to only show OS name. I have the modelChoice working but the text displayed is “tableName object (instance name)”

    I would like to determine how to display “instance name” only in the dropdown

Leave a Reply to arbadjie Cancel reply

Your email address will not be published. Required fields are marked *