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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:42:21+00:00 2026-06-03T15:42:21+00:00

I need to display a simple select input in a template. This input is

  • 0

I need to display a simple select input in a template.
This input is based on a selection of objects and should have an selected value.
It will not be used for any post to the server.

staffs = Staff.objects.filter(staff__company=comp)
selected_staff = staffs[0]

staffs are people that I need to display in the selection

I find this input quite verbose so I’m wondering if, instead of writing the input manually in the template, I should take advantage of a little form.

So the question is, should I write the <option> input manually or should I use the builtin widget ?

  • 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-03T15:42:22+00:00Added an answer on June 3, 2026 at 3:42 pm

    Using a built-in is always better. You can also use Field.initial to set an initial value for the field. Documetation is here

    Defining an option and set it on the template (probably using javascript) is much more harder.

    UPDATE:

    class MyStaffForm(forms.Form):
        <your form structure here>
        ...
        <end of your form structure>
    
    
    def Myview(request):
        ....
        staffs = Staff.objects.filter(staff__company=comp)
        #override form class to add a new form field
        MyStaffForm.base_fields['staff']=forms.ChoiceField(choices=[[(s.id, s) for s in staffs], initial=staff[0].id)
    

    This is how you handle the Form Class. But overriding base Form class using forms.ChoiceField is not a good choice since you use a queryset for defining choices. So use a ModelChoiceField instead

    MyStaffForm.base_fields['staff']=forms.ModelChoiceField(queryset=staffs, initial=staff[0])
    

    Django will handle the rest of the validation and initialization of the form…

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

Sidebar

Related Questions

I need some help with this one.... I have this simple model: public class
i'm using IE and I need to do a simple AJAX that will display
I have a simple css3 button and I need to align this button inside
I'm developing a simple web application where in I need to display number a
I need to display content from an OLAP cube in Sharepoint. This could be
I need to display a list of dates, which I have in a table
I have a simple messaging system, and I'd like to display both Received and
I need to create an HTML drop down that will display flags of countries.
When some one clicks a link I need the select box value to change
I have a table with 5 columns where I need the user to select

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.