title: Django: CreateView with additional field?
body: <p>I am trying to program a Django CreateView (CBV), which takes instead of the user id the user email and determines (or creates) the user based on the email.</p>
  
  <p>My model does not contain anything special:</p>
  
  <pre><code>class Project(models.Model):
      name = models.CharField(_('Title'), max_length=100,)
      user = models.ForeignKey(User, verbose_name=_('user'),)
      ...
  </code></pre>
  
  <p>My forms.py adds the additional email field to the form:</p>
  
  <pre><code>class ProjectCreateForm(forms.ModelForm):
      email = forms.EmailField(required=True, )
  
      class Meta:
          model = Project
          fields = ('name', ...,)
  </code></pre>
  
  <p>In my views.py, I am trying to determine if the user exists or should be created. In both cases, the user id should be saved as part of the Project instance.</p>
  
  <pre><code>class ProjectCreateDetails(CreateView):
      form_class = ProjectCreateForm
      template_name = '...'
      success_url = reverse_lazy('login') 
      model = Project
  
      def form_valid(self, form):
          try:
              user = User.objects.get(email=form.email)
          except User.DoesNotExist:
              user = User.objects.create_user(form.email, form.email, ''.join([random.choice(string.digits + string.letters) for i in range(0, 10)]))
              user.save()
          form.instance.user = user
          return super(ProjectCreateDetails, self).form_valid(form)
  </code></pre>
  
  <p><strong>However I am facing an error that the <code>'Solution' object has no attribute 'email'</code>.</strong> </p>
  
  <p>Do I need to switch to a FormView instead of a CreateView?</p>