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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:42:48+00:00 2026-05-28T01:42:48+00:00

I think I am missing a key fundamental of how to use a ModelForm

  • 0

I think I am missing a key fundamental of how to use a ModelForm and Forms to save data in my database. I have a UserProfile model that is stores specific data that is not included in the User class

Models.py:

class UserProfile(models.Model):
    GRADE_YEAR_CHOICES = (
        ('FR', 'Freshman'),
        ('SO', 'Sophomore'),
        ('JR', 'Junior'),
        ('SR', 'Senior'),
        ('GR', 'Graduate')
    )

    school = models.CharField(max_length=64)
    grade_year = models.CharField(max_length=2, choices=GRADE_YEAR_CHOICES)
    gpa = models.DecimalField(decimal_places=2, max_digits=6, blank=True, null=True)
    user = models.ForeignKey(User, unique=True)

My Forms.py looks like:

class UserProfileForm(ModelForm):
    class Meta:
        model = UserProfile

The View for this looks like:

def more(request):
    if request.method == 'POST':
        form = UserProfileForm(request.POST)
        if form.is_valid():
            form = UserProfileForm(request.POST,
                school = form.cleaned_data['school'],
                grade_year = form.cleaned_data['grade_year'],
                gpa = form.cleaned_data['gpa'],
                user = form.cleaned_data['user']
            )
            form.save()
            return HttpResponseRedirect('/success')
    else:
        form = UserProfileForm()

        variables = RequestContext(request, {
            'form': form
        })
        return render_to_response('more.html', variables)

The form renders correctly with all of the fields from the model that I specified but when I try to save the data I get:

__init__() got an unexpected keyword argument 'grade_year'

What am I missing here? I realize that I might be missing a big concept so any help would be greatly appreciated.

  • 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-28T01:42:49+00:00Added an answer on May 28, 2026 at 1:42 am

    You are passing UserProfileForm a keyword argument that refers to your model fields which it isn’t expecting.

    Simply call save() after the form is instantiated – if it had cleaned_data (i.e. the form is valid), then the POSTed fields are already mapped to the instance via ModelForm magic.

       if form.is_valid():
                form.save()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think I'm missing something fundamental about password based data encryption. A tool that
I have a database with one row of data that will be used across
OK I have looked and looked and I think I am missing something about
I'm obviously missing something fundamental here. I have the following Scala Code: package org.carlskii
I think I'm missing some key concept regarding objects and prototype functions in JavaScript.
I think I'm missing something obvious with doctrine relationship mapping. I have two models,
I think I'm missing something really obvious here... must be... but for some reason
I think I am missing something about correct behaviour of Monitor.Enter and Monitor.TryEnter .
I think I am missing smth back in my theoretical background on this thing.
I think I'm missing something very obvious and its making my brain hurt. class

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.