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

  • Home
  • SEARCH
  • 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 8205611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:18:53+00:00 2026-06-07T08:18:53+00:00

I have a select box that may have option with values in -20 and

  • 0

I have a select box that may have option with values in -20 and +20 range:

class MyForm(forms.ModelForm):
    class Meta:
        i0=xrange(-20, 20, 0.25)
        c = tuple(("%g" % x , "%g" % x) for x in i0)
        model = MyModel
        widgets = {
            'my_field' : forms.Select(choices=c),

        }

Output is:

<select>
    <option value="-20">-20</option>
    <option value="-19.75">-19.75</option>
    <option value="-19.5">-19.5</option>
    <option value="-19.25">-19.25</option>
    <option value="-19">-19</option>
    .
    .
    .
    <option value="19">19</option>
</select>

But I want a ‘+’ symbol in positive digits. i0=xrange(-20, +20, 0.25) not solving the issue. How can I add ‘+’ symbol in positive digits in options?

Thanks in advance

  • 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-07T08:18:55+00:00Added an answer on June 7, 2026 at 8:18 am

    Without access to a machine with python I cant test but you should be able to do:

      c = tuple(("%g" % x , "%+g" % x) for x in i0)
    

    http://docs.python.org/release/3.0/library/stdtypes.html#old-string-formatting-operations

    Should also work in earlier python versions

    EDIT:- to remove the + from a Zero value:

     c = tuple(("%g" % x , "%+g" % x) for x in i0 if x != 0 else ("0", "0"))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a select box that is being populated dynamically from a database. As
I have a select box that needs to submit it's value to a server
I am using chosen.js ( http://harvesthq.github.com/chosen/ ) and I have a select box that
here is my situation. I have a select box that is populated from a
I want to have on my site a single select box that will then
I have a select box on a page that does a post with jQuery
We have a custom JSF component that renders some buttons and a select box
I have a select box that when clicked on it (and run jQuery code
I have a select box that when I select a country the map gets
I have a select box and an input box that submits to a view

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.