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 6752303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:01:43+00:00 2026-05-26T13:01:43+00:00

I dont know if I am doing this in the right manner. I have

  • 0

I dont know if I am doing this in the right manner.

I have a form:

class ConnectSelectMultipleForm(forms.Form):
    class Meta:
        model = Connect

    def __init__(self, *args, **kwargs):
        messages = kwargs.pop('messages')
        choices = []
        if messages:
            pass
        else:
            messages = []

        for message in messages:
            index = (message.id, {message.sender, message, message.id})
            choices.append(index)

        super(ConnectSelectMultipleForm, self).__init__(*args, **kwargs)
        self.fields['message'] = forms.MultipleChoiceField(choices=choices,
                                     widget=forms.CheckboxSelectMultiple)

As can be seen above i am sending {message.sender, message ,message.id} to the template. Now i want to access these variables in the template.

{% for field in select_form %}       
    {% for fi in field %}
        {{ fi.message }}
        {{ fi.message.sender }}
        {{ fi.message.id }}
    {% endfor %}
{% endfor %}

The above code is wrong. But can we do something similar to this? Or is there an alternative method to do what i am trying to do?

Thanks in advance.

###Edit

The ouput i am getting by just printing the field is as follows

 set([5, u'Everycrave', <Connect: The deal you refered has been bought>])

What i want is

Id : 5 ,Name : Everycrave , Content : The deal you refered has been bought

So I want those fields individually

  • 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-26T13:01:44+00:00Added an answer on May 26, 2026 at 1:01 pm

    You don’t want to “iterate over the field” at all. Django does this for you. The only issue you have is how to create the display value for the field’s choices – for some reason, you’re creating them as sets, when you just want a string. Your __init__ method should be something like this:

    def __init__(self, *args, **kwargs):
        messages = kwargs.pop('messages', None)
        super(ConnectSelectMultipleForm, self).__init__(*args, **kwargs)
        if messages is None:
            messages = []
    
        choices = [(message.id, "%s: %s (%s)" % message.sender, message.text, message.id)
                   for message in messages]
    
        self.fields['message'].choices = choices
    

    Now you simply refer to the field in the template in the normal way: {{ form.message }}.

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

Sidebar

Related Questions

I'm doing this easy horizontal menu but I'm facing a funny issue... Dont know
I don't know what's the best way to doing this. On my application.html.erb I
I'm mot sure if I'm doing this wrong or not I don't know if
I don't know what I'm doing wrong here. I have a ListBox whose DataContext
I dont know where my error is in this mysql query $sql = INSERT
i have this issue working but i would like to know if there is
I am soo angry right now. I lost hours and i dont know why
Ok.. This might be the duplicate.. but I dont think I even know the
I have this problem, right now when I do a search like: really long
I have already posted another question about this, but no one seemed to know

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.