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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:30:40+00:00 2026-05-28T15:30:40+00:00

I have field in my model: TYPES_CHOICES = ( (0, _(u’Worker’)), (1, _(u’Owner’)), )

  • 0

I have field in my model:

TYPES_CHOICES = (
    (0, _(u'Worker')),
    (1, _(u'Owner')),
)
worker_type = models.PositiveSmallIntegerField(max_length=2, choices=TYPES_CHOICES)

When I use it in ModelForm it has “———” empty value. It’s TypedChoiceField so it hasn’t empty_label attribute., so I can’t override it in form init method.

Is there any way to remove that “———“?

That method doesn’t work too:

def __init__(self, *args, **kwargs):
        super(JobOpinionForm, self).__init__(*args, **kwargs)
        if self.fields['worker_type'].choices[0][0] == '':
            del self.fields['worker_type'].choices[0]

EDIT:

I managed to make it work in that way:

def __init__(self, *args, **kwargs):
    super(JobOpinionForm, self).__init__(*args, **kwargs)
    if self.fields['worker_type'].choices[0][0] == '':
        worker_choices = self.fields['worker_type'].choices
        del worker_choices[0]
        self.fields['worker_type'].choices = worker_choices
  • 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-28T15:30:41+00:00Added an answer on May 28, 2026 at 3:30 pm

    The empty option for any model field with choices determined within the .formfield() method of the model field class. If you look at the django source code for this method, the line looks like this:

    include_blank = self.blank or not (self.has_default() or 'initial' in kwargs)
    

    So, the cleanest way to avoid the empty option is to set a default on your model’s field:

    worker_type = models.PositiveSmallIntegerField(max_length=2, choices=TYPES_CHOICES, 
                                                   default=TYPES_CHOICES[0][0])
    

    Otherwise, you’re left with manually hacking the .choices attribute of the form field in the form’s __init__ method.

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

Sidebar

Related Questions

I have following model. class Comment(models.Model): type = models.CharField(max_length=21, choices=OBJECT_TYPE_CHOICES) program = models.ForeignKey(Program, db_column='object_id',
I have a CharField type with a choices field as follows: class Thing(models.Model): def
I have model: # encoding: utf-8 class Tag include Mongoid::Document field :name, type: String
I have a model: class SimpleAction include Mongoid::Document field :set_date, :type => Date and
I have three models: class User include Mongoid::Document field :name, :type => String has_many
I have a field on my User model that is protected because it determines
I have written a custom Django Model Field to store dateutil.relativedelta 's. The field
I have the following field : @Html.TextBoxFor(model => model.Patient.dateOfBirth, new { id = datepicker,
I'd like to have access to one my model field verbose_name. I can get
I'm doing this query: SomeObject.objects.annotate(something=Avg('something')).order_by(something).all() I normally have an aggregate field in my model

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.