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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:07:46+00:00 2026-06-02T16:07:46+00:00

so new to python & django moving along nice on a project but cant

  • 0

so new to python & django moving along nice on a project but cant find any simple answers to the above question:

Models are like this

class Projects(models.Model):
    project_name = models.CharField(max_length=200)
    project_description = models.TextField(blank=True)    
    active = models.BooleanField() 

    def __unicode__(self):
        return self.project_name

I have other models that refer to the above as a ForignKey like

class Estimates(models.Model):
    client = models.ForeignKey(Clients)
    estimate_summary = models.CharField(max_length=200,blank=True)
    project = models.ForeignKey(Projects,default=-1,blank=True)

I know I can set blank=False to ensure I am getting a valid choice, however I want to allow them the option of not assigning a project to the estimate, in which case I would store a default integer -1 or something.

Problem however is I cant figure how to get the form to use an Integer as its default value instead of ” ” <- (empty string)

<option selected="selected" value="">---------</option>
<option value="1">Sample Project</option>

All the questions and answers I have seen revolve around changing the --------- to some other text or forcing you to remove the blank option all together. I just want

<option selected="selected" value="-1">---------</option>

So my form will validate

When finished writing the question I wondered if I could insert an option myself and use empty_label=None when adding to the form

field2 = forms.ModelChoiceField(queryset=..., empty_label=None)
  • 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-02T16:07:47+00:00Added an answer on June 2, 2026 at 4:07 pm

    First of all, you don’t want to use an Integer of -1 as default. For ForeignKeys you usually use null=True in combination with blank=True if you don’t require it (Don’t forget to drop and recreate the table or use south to migrate it — also remove default then since None is a valid option with null=True and as such no default is required). This way if you don’t assign a project you will get NULL in the database which is also what the Admin supports — -1 will break more than it solves.

    As soon as you use null=True, blank=True ModelChoiceField will automatically work as you want.

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

Sidebar

Related Questions

I am new to Django & Python and have been following a tutorial, but
I'm new to Python & Django. I want to allow users to create new
Learning django & python. Just set up a new site after doing the tutorial.
I'm new to Django and python. I've done login forms but I need to
New to Python, have a simple, situational question: Trying to use BeautifulSoup to parse
I'm new to python but I've run into a hitch when trying to implement
To preface I'm very new to python (about 7 days) but I'm an experienced
So I'm just learning some new stuff in C# & Python. Turns out both
I have an OSQA (python / django q&a application) installation serving 8 different sites.
I really new to Python and coding in general, but I have been making

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.