title: Register Form not saving to database: Django?
body: <p><em>Weird issue with by registration form, not sure i am doing wrong.</em></p>
  
  <p>I have <code>StudentProfile</code> Model, that I am trying to save data from <code>StudentResistrationForm</code> but the <strong>data is not being saved into database</strong></p>
  
  <blockquote>
    <p>ERROR: NameError at /register/ name 'StudentProfile' is not defined</p>
  </blockquote>
  
  <p><strong><em>Is the view logic correct? What am I missing? Ideas please</em></strong></p>
  
  <p>model</p>
  
  <pre><code>class Accounts(AbstractUser):
      email = models.EmailField('email address', unique=True)
      first_name = models.CharField('first name', max_length=30, blank=True)
      last_name = models.CharField('last name', max_length=30, blank=True)
      date_joined = models.DateTimeField('date joined', auto_now_add=True)
  
      # asdd
      bio = models.TextField(max_length=500, blank=True)
      location = models.CharField(max_length=30, blank=True)
      birth_date = models.DateField(null=True, blank=True)
  
  
  class StudentProfile(models.Model):
      user = models.OneToOneField('Accounts', related_name='student_profile')
      # additional fields for students
      AMEB_Ratings = models.PositiveIntegerField(default=0)
      is_student = models.BooleanField('student status', default=False)
  </code></pre>
  
  <p>form</p>
  
  <pre><code>class StudentResistrationForm(forms.ModelForm):
      class Meta:
          model = StudentProfile
          fields = (  
              'AMEB_Ratings',
  
          )
  
      def save(self, commit=True):
          user = super(StudentResistrationForm, self).save(commit=False)
          # user.first_name = self.cleaned_data['first_name']
          # user.last_name = self.cleaned_data['last_name']
          user.AMEB_Ratings = self.cleaned_data['AMEB_Ratings']
  
          if commit:
              user.save()
  
          return user 
  
      class UserForm(forms.ModelForm):
          class Meta:
              model = get_user_model()
              fields = ('username', 'email', 'password')
  </code></pre>
  
  <p>view</p>
  
  <pre><code>def registerStudent(request):
      # Once register page loads, either it will send to the server POST data (if the form is submitted), else if it don't send post data create a user form to register
      if request.method == "POST":
          user_form = UserForm(request.POST)
          form = StudentResistrationForm(request.POST)
  
          if form.is_valid() and user_form.is_valid():
              User = get_user_model()
              username = user_form.cleaned_data['username']
              email = user_form.cleaned_data['email']
              password = user_form.cleaned_data['password']
              new_user = User.objects.create_user(username=username, email=email, password=password)
  
              Student_profile = StudentProfile()
              Student_profile.user = new_user
              Student_profile.AMEB_Ratings = request.POST['AMEB_Ratings']
              # Student_profile = StudentProfile.create_user(AMEB_Ratings=AMEB_Ratings)
              new_user.save()
              Student_profile.save()
              # form.save()
  
              # AMEB_Ratings = form.cleaned_data['AMEB_Ratings']
              return redirect('/')
      else:
          #  Create the django default user form and send it as a dictionary in args to the reg_form.html page.
          user_form = UserForm()
          form = StudentResistrationForm()        
  
          # args = {'form_student': form, 'user_form': user_form }
      return render(request, 'accounts/reg_form_students.html', {'form_student': form, 'user_form': user_form })
  </code></pre>