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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:32:20+00:00 2026-05-31T16:32:20+00:00

Is it possible in django to have a ChoiceField on a formset level rather

  • 0

Is it possible in django to have a ChoiceField on a formset level rather than an inline form? So for example if I have a formset for phones and each inline form represents a single Phone model, how can I have a ChoiceField that spans all the inline forms? Something like this where I’m choosing a primary phone:

Complex ChoiceField

My models:

class Profile(models.Model):
    verified = models.BooleanField(default=False)
    primary_phone = models.OneToOneField('Phone', related_name='is_primary', null=True, blank=True)

class Phone(models.Model):
    profile = models.ForeignKey(Profile, editable=False)
    type = models.CharField(choices=PHONE_TYPES, max_length=16)
    number = models.CharField(max_length=32)

    @property
    def is_primary(self):
        return profile.primary_phone == self

I can always remove primary_phone and use a BooleanField in Phone to indicate if it’s primary or not, but I’m not sure if this going to help my problem.

I’m also looking for a less-hacky more-django-like approach if possible.

  • 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-31T16:32:22+00:00Added an answer on May 31, 2026 at 4:32 pm

    There is no way to have django create this for you automatically. In your ModelForm (that’s used in the inline) I’d add a boolean field called is_primary. This field will then show up on each inlined Phone instance (as a checkbox).

    On the front end sort it out with javascript so that a user can only select one default at a time. On the back end use some custom validation to double check that only one is_default was submitted, and then update the primary_phone as necessary with form logic.

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

Sidebar

Related Questions

Is it possible to customize a django application to have accept localized date format
Is is possible to programatically join two tables using Django's ORM? I have two
can anybody post the simplest possible example for django-ajax-selects ? Just one model with
Is it possible to read a Django model's fields' options? For example, with the
I have just started learning django. I created a form from django models. On
Is possible in Django to have a sub_app? Project->Intranet->sub_app1 Project->Intranet->sub_app2 Project->Catalog Project->App
Possible Duplicate: Django Enter a list of values form error when rendering a ManyToManyField
For example: I have a user that wants to create a contact form for
Here is what I have, a simple Django form class survey (forms.Form): answer =
Possible Duplicate: Django models: default value for column I have created a model field

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.