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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:02:04+00:00 2026-05-31T00:02:04+00:00

How do you get a MultipleChoiceField() to correctly load initial values? I have a

  • 0

How do you get a MultipleChoiceField() to correctly load initial values?

I have a Django model with a CharField, which I’m rendering in admin as a MultipleChoiceField() because I want to limit its value to one or more specific choices.

My code looks something like:

class MyModelInlineForm(ModelForm):

    my_text_field = forms.MultipleChoiceField(required=False)

    def __init__(self, *args, **kwargs):
        super(MyModelInlineForm, self).__init__(*args, **kwargs)

        self.fields['my_text_field'].choices = get_choices(self.instance)

        if self.instance:
            self.fields['my_text_field'].initial = self.instance.my_text_field

class MyModelInline(admin.TabularInline):
    model = MyModel
    form = MyModelInlineForm
    extra = 0

It seems to render fine, but when I select values and save, the new form loads with no values selected. I’ve confirmed the value is being correctly saved in the database, but the form isn’t loading it, and I’m not sure why.

Based on some similar questions, I tried explicitly setting the initial value of my model’s saved field, but this appeared to have no effect.

What am I doing wrong?

  • 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-31T00:02:05+00:00Added an answer on May 31, 2026 at 12:02 am

    You need to set the value in the form’s initial (a dictionary), not the field’s:

    if self.instance:
        self.initial['my_text_field'] = self.instance.my_text_field
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MultipleChoiceField on a form holding car makes. I want to filter
I get an XML file From a web service. Now I want to get
Get location(lat/long) without GPS, just like my location feature in Google maps. I have
Get month of a given date which is stored in a PHP time variable
I don't understand what's happening, I have in my form mylist = forms.MultipleChoiceField(required=False, widget=forms.SelectMultiple,
I have some models and I want to generate a multi-selection form from this
Get the following error periodically in an IIS application: Failed to load resources from
How do I get the choices field values and not the key from the
I have a model with field: class Movie(models.Model): genre = models.CommaSeparatedIntegerField(max_length=100, choices=GENRE_CHOICES, blank=True, default=0)
I have a django form that allows a user to select multiple options: CARDS

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.