title: Complicated Django ModelForm validation with OneToOneField and customed argument
body: <p>Sorry for the lengthy question. I have a complicated situation with django modelform validation. I have a model UserProject ready and created many objects. I also have another model Action_Inputs to accept multiple parameters, which is a onetoonefield relation with UserProject. I do need customed input argument for one field of Action_Inputs. But I cannot have the form valided. </p>
  
  <p>models.py</p>
  
  <pre><code>class UserProject(models.Model):
      pid = models.CharField(max_length=10, null=False, unique=True)
      email = models.EmailField(max_length=254, null=False)
      directory = models.CharField(max_length=255)
  
  class Action_Inputs(models.Model):
      userproject = models.OneToOneField(UserProject, null=False)
      method = models.CharField(max_length=255)
      file = models.FileField(upload_to='userdata')
  </code></pre>
  
  <p>Now I have the following ModelForm which takes a customed input argument jobid, catched from url, which is a string to get back to the previous UserProject pid:</p>
  
  <pre><code>class ActionInputsForm(ModelForm):
  
      def __init__(self, jobid, *args, **kwargs):
          super(ActionInputsForm, self).__init__(*args, **kwargs)
          self.fields['userproject'].initial = jobid
  
      class Meta:
          model = Action_Inputs
          fields = ['userproject', 'method', 'file'] # userproject will be hidden
  
      def clean_userproject(self):
          userproject = self.cleaned_data['userproject']
          if len(userproject) != 10:
              raise forms.ValidationError("---PID error.")
          return UserProject.objects.get(pid=userproject)
  
      def clean(self):
  
          return self.cleaned_data
  </code></pre>
  
  <p>In my views.py</p>
  
  <pre><code>def parameters_Inputs(request, jobid):
  
      if request.method == "POST":
          form1 = ActionInputsForm(request.POST, request.FILES, jobid)
  
          if form1.is_bound:
              form1.save()
              return render(request, 'goodlog.html', {'jobid': jobid})
  
      elif request.method == "GET":
          form1 = ActionInputsForm(jobid)
  
      return render(request, 'inputsform.html',
          {'form1': form1, 'jobid': jobid})
  </code></pre>
  
  <p>Now the request.POST['userproject'] is empty, which means the jobid has not been modified by <strong>init</strong>, the request.FILES looks correct but the validation is false. It says Unicode   object has no attrite get, which is related to the uploaded file. Any idea about what is wrong? Thanks very much. </p>
  
  <p>The following works:(thanks to Vladimir Danilov)</p>
  
  <pre><code>def __init__(self, jobid, *args, **kwargs):
      super(ActionInputsForm, self).__init__(*args, **kwargs)
      self.fields['userproject'].initial = UserProject.objects.get(pid=jobid)
  
  
  def clean_userproject(self):
      userproject = self.cleaned_data['userproject']
      if not userproject:
          raise forms.ValidationError("---UserProject not found.")
      return userproject
  </code></pre>
  
  <p>def parameters_Inputs(request, jobid):</p>
  
  <pre><code>if request.method == "POST":
      form1 = ActionInputsForm(jobid, request.POST, request.FILES)
  </code></pre>
  
  <p>.......</p>