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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:07:34+00:00 2026-06-14T15:07:34+00:00

I have two models that are linked by ForiegnKey, and I’d like to use

  • 0

I have two models that are linked by ForiegnKey, and I’d like to use the fields in the PhoneNumber model for my form, using django-crispy-forms.

What I’ve tried is using the syntax ‘phone_number__number’, but that only gives me an empty drop down list in the form.

Here are my models, with everything but phone_number taken out of the Customer model for this post:

class Customer(models.Model):
  phone_number = models.ForeignKey(PhoneNumber)

class PhoneNumber(models.Model):
  TYPES = (
      ('Cell', 'Cell'),
      ('Home', 'Home'),
      ('Fax', 'Fax'),
      ('Work', 'Work'),
  )
  primary = models.BooleanField(default=False)
  phone_type = models.CharField(max_length=30, choices=TYPES, default='Cell')
  number = models.CharField(max_length=15)

And my form, with only the phone_number field:

class CustomerCreateForm(forms.ModelForm):
 '''
 Base form for creating customers
 '''
 def __init__(self, *args, **kwargs):
     self.helper = FormHelper()
     self.helper.layout = Layout(
         Fieldset(
             'Personal Information',
             'phone_number__number',
         ),
         FormActions(
             Submit('submit' , 'Submit' , css_class='btn btn-success'), 
             Button('cancel' , 'Cancel' , css_class='btn btn-warning', onclick='javascript:history.go(-1);'), 
         )
     )
     super(CustomerCreateForm, self).__init__(*args, **kwargs)

 class Meta:
     model = Customer
     exclude = (
         'create_user',
         'modify_user'
     )
  • 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-14T15:07:35+00:00Added an answer on June 14, 2026 at 3:07 pm
    from yourapp.models import PhoneNumber    
    
    class CustomerCreateForm(forms.ModelForm):
        '''
        Base form for creating customers
        '''
        def __init__(self, *args, **kwargs):
            self.helper = FormHelper()
            self.helper.layout = Layout(
                Fieldset(
                    'Personal Information',
                    'phone_number',
                ),
             FormActions(
                 Submit('submit' , 'Submit' , css_class='btn btn-success'), 
                 Button('cancel' , 'Cancel' , css_class='btn btn-warning', 
                        onclick='javascript:history.go(-1);'), 
                 )
             )
             super(CustomerCreateForm, self).__init__(*args, **kwargs)
             self.fields["phone_number"].choices = \
             [(item.number, item.number) for item in PhoneNumber.objects.all()]
    
             class Meta:
                 model = Customer
                 exclude = (
                     'create_user',
                     'modify_user'
                 )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two models in Django linked together by ManyToMany relation like this: class
I have two models that are linked by another model through a many to
Let's assume I have two gmdistibution models that i obtained using modeldata1=gmdistribution.fit(data1,1); modeldata2=gmdistribution.fit(data2,1); Now
I have two models User and Admin(with RailsAdmin) that use Devise. I sign in
I have two models that are related together using ForeignKey and related_name is used.
I have three models linked by foreign keys: class One(models.Model): ... class Two(models.Model): one
I have two models that are associated with each other. Customer has_one :primary_contact And
If I have two models that are very different, is it defeating the purpose
If I have two models that are guaranteed to have a one-to-one correspondence, i.e.
I have a two models that are similar, but not exactly the same. Here's

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.