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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:27:30+00:00 2026-05-25T10:27:30+00:00

I have UerProfile defined and need to take phone data for MyForm class UserProfile(models.Model):

  • 0

I have UerProfile defined and need to take phone data for MyForm

 class UserProfile(models.Model):
     ...
     phone = models.CharField(max_length=20, blank=True)


 class CustomModel(models.Model):
     ...
     phone = models.CharField(max_length=20)


 class MyForm(forms.ModelForm):

     class Meta:
         model = CustomModel
         exclude = ['some_fields_but_not_phone',]

Now I need to take phone data from UserProfile if it is set, to be prepopulated value in {{ form.phone }} field. Then user can change it or leave it as is when he submit form.

  • 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-25T10:27:31+00:00Added an answer on May 25, 2026 at 10:27 am

    One solution, though maybe not the most elegant, is to bind data from a dictionary to your MyForm object in your view.

    data = {
        'field1': 'data'
        'field2': 'data'
        'phone': request.user.get_profile().phone
    }
    form = MyForm(data)
    

    More info here: https://docs.djangoproject.com/en/1.3/ref/forms/api/

    Only populating this field if ‘phone’ is set is pretty trivial from here.

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

Sidebar

Related Questions

I have such models: class LifeGoals(models.Model): name = models.CharField(max_length=200) class Interests(models.Model): name = models.CharField(max_length=200)
I have an extended UserProfile model in django: class UserProfile(models.Model): user = models.ForeignKey(User, unique=True)
I have following model: class UserProfile(models.Model): User profile model, cintains a Foreign Key, which
I have the following model set up: class UserProfile(models.Model): Additional attributes for users. url
I have the following models -- class UserProfile(models.Model): user = models.ForeignKey(User, unique=True) ... class
I have the following models: class UserProfile(models.Model): user = models.OneToOneField(User) score = models.PositiveIntegerField() class
I have the the following Django model: class UserProfile(models.Model): user = models.ForeignKey(User, unique=True) full_name
I have a model with a DateField : class Info(models.Model): userprofile = models.OneToOneField(UserProfile, primary_key=True)
I have django model: class UserProfile(models.Model): user = models.OneToOneField(User) #other fields When I create
I have this model: class UserProfile(models.Model): (UserProfile description) user = models.ForeignKey(User) image = models.ImageField(upload_to=upload_to)

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.