Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3798478
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:34:44+00:00 2026-05-19T13:34:44+00:00

I am trying to display the data from a ModelMultipleChoiceField, and have tried to

  • 0

I am trying to display the data from a ModelMultipleChoiceField, and have tried to iterate for the objects, but I am getting funky results. Thanks for the help!

{{ chef.meal }} 

Renders

[<Meal: Breakfast>, <Meal: Brunch>]

—

{% for i in chef.meal%} {{i}} {% endfor %}

Renders

[ < M e a l : B r e a k f a s t > , < M e a l : B r u n c h > ]

Here is the way I have the ModelMultipleChoiceField set up:

  meal = forms.ModelMultipleChoiceField(
        label=_("What is your best meal?"),
        queryset=Meal.objects.all(),
                                        required=True)

And the Meal model:

class Meal(models.Model):
  name = models.CharField(max_length=10)

  def __unicode__(self):
    return "%s" % self.name

HttpResponse:

  data = {"profile":profile,
          "chef":chef}
  return render_to_response(template_name,
                            data,
                            context_instance=RequestContext(request))

I am passing ‘chef’ through to the template, and then pulled the meals from the Chef object.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T13:34:45+00:00Added an answer on May 19, 2026 at 1:34 pm

    You cannot use form fields inside a model. Instead make a foreign key from meal to Chef.

    class Meal(models.Model):
        name = models.CharField(max_length=10)
        chef = models.ForeignKey(Chef)
        def __unicode__(self):
            return "%s" % self.name
    

    Now inside the template use

    {% for meal in chef.meal_set.all %}
         {{ meal }}
    {% endfor %}
    

    Ofcourse, instead of foreign field, there can be multiple-multiple relations between chef and meal models. Modify the code accordingly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to display data from table games_reviews but instead I am getting
I'm trying to display set of data which have retrieved from the sql database
I'm trying to display data from an array of objects obtained using another company's
I have a plist that I am trying to pull data from to display
I'm getting error Not unique table/alias while trying to display data from MySQL database
I am getting the data from sqlite database and trying to display it in
I'm trying to get ReportViewer to display data from a BindingSource (VB.Net Winforms). I
I am trying to have a tree display custom data that looks like this.
i am trying to display data from a database to the text box and
I'm trying to display data from my database in a ListFragment. To do this,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.