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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:04:50+00:00 2026-05-23T02:04:50+00:00

I have a modelform set up for a user to enter his contact info.

  • 0

I have a modelform set up for a user to enter his contact info. The validation and form.is_valid() method is working, however the request.POST data is not being stored to the db, and I’m having trouble figuring out what the problem is. Here is what I currently have —

# model
class UserProfile(models.Model):
    user = models.ForeignKey(User, unique=True)
    contact_email = models.EmailField(max_length=100, blank=True)
    contact_phone = models.IntegerField(max_length=11, blank=True)
    website = models.CharField(max_length=256, blank=True)

class ContactInfoForm(ModelForm):
    class Meta:
        model = UserProfile
        fields = ('contact_email', 'contact_phone', 'website',)

# view
@login_required
def edit_contact(request):
    contact_email = request.user.get_profile().contact_email
    form = ContactInfoForm(initial={'contact_email':contact_email,})
    if request.method == 'POST':
        form = ContactInfoForm(request.POST, instance=request.user)
        if form.is_valid():
            form.save()
    return render_to_response(...)

# template
<form action="." method="post"> {% csrf_token %}
    <table>
        {{form}}
    </table>
    <p><input type="submit" name="save_changes" value="Save Changes" ></p>
</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-23T02:04:51+00:00Added an answer on May 23, 2026 at 2:04 am

    I think the error might be the instance you’re calling in your ModelForm. You need to use a UserProfile instance, but you’re using a User instance. The following might work (untested):

    @login_required
    def edit_contact(request):
        contact_email = request.user.get_profile().contact_email
        form = ContactInfoForm(initial={'contact_email':contact_email,})
        user_profile = UserProfile.objects.get(contact_email=contact_email)
        if request.method == 'POST':
            form = ContactInfoForm(request.POST, instance=user_profile)
            if form.is_valid():
                form.save()
        return render_to_response(...)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model form that contains a DecimalField() with max_digits set to 5.
In a ModelForm, i have to test user permissions to let them filling the
I Have this Form class MyModelForm(forms.ModelForm): boolfield = forms.TypedChoiceField(coerce=bool, choices=((False, 'No'), (True, 'Yes')), widget=forms.RadioSelect
I have a form which I want the user to be able to export
I currently have a ModelForm set up in Django, but would like to make
I have a custom ChangeUserForm (ModelForm on User) that allows a user to update
I have a form where a user logs in with a google account and
I have the following form: class FeaturedVideoForm(ModelForm): featured_video = forms.ModelChoiceField(Video.objects.none() widget=make_select_default, required=False, empty_label='No Featured
I need set field value, not passed to Django Form constructor. I have model
@login_required def post_review(request): if request.method == 'POST': formset = ReviewForm(request.POST) if formset.is_valid(): formset.save(commit=False) #formset.author

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.