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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:58:54+00:00 2026-06-15T17:58:54+00:00

This has been driving me nuts and I can’t get it to work. It’s

  • 0

This has been driving me nuts and I can’t get it to work. It’s a simple scenario: I want to present the user with a dynamically generated list of users that I pull from the database so the user can select one of the users from a ChoiceField (rendered as an HTML select) and click a “Get Data” button.

I don’t want to create a list of the users in the form because new users will come along all the time. I want to query for the users in my view and bind that list of users to the form so I can always render the latest list of users. So here’s my form:

class ViewUsersForm(forms.Form):
  user_choice = forms.ChoiceField()

And here’s my view:

from django.contrib.auth.models import User
from mystuff.forms import ViewUsersForm

def site_admin_view_user_groups_page(request):
  if request.method == 'POST':
    <...handling POST for this question is unimportant...>
  else:
    users = User.objects.all()
    data = {'user_choice': users}
    form = ViewUsersForm(data) # binding the list of users here

  variables = RequestContext(request, {'form': form,})
  return render_to_response('school/admin/view_user_groups_page.html', variables)

And finally, here’s the template I’m rendering to:

<form action="/site/viewusers/" method="post">{% csrf_token %}
  {{ form.user_choice }}
  <button type="submit" name="getDataButton">Get Data</button>
</form>

So when the template renders the bound form (form = ViewUsersForm(data)), the ChoiceField comes up empty. How do I get the data in the ChoiceField to render in my HTML??? What really simple thing am I missing here? Or am I going about this the completely wrong way?

  • 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-06-15T17:58:56+00:00Added an answer on June 15, 2026 at 5:58 pm

    The ChoiceField takes ‘An iterable (e.g., a list or tuple) of 2-tuples to use as choices for this field.’ So you would need to setup your choices as ((value1, ‘name1’),(value2, ‘name2’),())
    https://docs.djangoproject.com/en/dev/ref/forms/fields/#django.forms.ChoiceField

    You could also use the ModelChoiceField to use your queryset as-is
    https://docs.djangoproject.com/en/dev/ref/forms/fields/#django.forms.ModelChoiceField

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

Sidebar

Related Questions

This problem has been driving me nuts for a while now, and I can't
this has been driving me nuts because i know theres a simple solution but
(This should be simple. But it has been driving me nuts for many hours.)
This has been driving me nuts. I keep getting the following exception System.InvalidOperationException: The
This has been driving me nuts. I hope it's not been asked before but
he this has been driving me nutts, and I hope someone can shed some
This has been driving me nuts for a week now. I have a class
This has been driving me nuts, I'm posting here after a lot of looking
This has been driving me nuts all day. I've seen this problem crop up
This has been driving me nuts all day. I have a weird bug that

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.