title: Django: How do I add data to a ModelForm subclass before validation?
body: <p>As part of a form validation in Django, I want to check when a user last made a post. </p>
  
  <p>I've had a look at <a href="https://stackoverflow.com/questions/5785727/accessing-request-user-in-class-based-generic-view-createview-in-order-to-set-fk">this</a>, and <a href="https://stackoverflow.com/questions/5666505/how-to-subclass-djangos-generic-createview-with-initial-data">this</a> question on stackoverflow, which appear to address this issue, and initially used the accepted answer <a href="https://stackoverflow.com/questions/5785727/accessing-request-user-in-class-based-generic-view-createview-in-order-to-set-fk/5785767#5785767">here</a>. Essentially the process at the moment has been to add the request.user object during the </p>
  
  <pre><code>def form_valid(self, form):
  </code></pre>
  
  <p>method of the CreateView subclass. However, this doesn't allow the user variable to be used during form validation.</p>
  
  <p>Since I want to access the user variable during validation, as the check on time since last post is logically validation, I need the user variable injected to the form earlier.</p>
  
  <p>I've tried altering the get_initial() method:</p>
  
  <pre><code>def get_initial(self):
      initial = super(ArticleCreateView, self).get_initial()
      initial['user'] = self.request.user
      return initial
  </code></pre>
  
  <p>This successfully sets the ['user'] key in the initial dictionary, but this never makes it through the cleaning process, which deals only with the stuff in the ['data'] dictionary, and removes anything in initial. I've deliberately excluded user from the form display, but this appears to also remove it from the cleaning process and validation.</p>
  
  <p>Is the correct way to do this to override the <strong>init</strong>() method of the Form, and the get_initial() method of the view, putting 'user' into initial, and then the form pulling the extra information from initial into the form at <strong>init</strong>()?</p>
  
  <p>I'm looking to pass the request.user to the form, and then I can access it within the form-wide clean() method to do the additional checks, which amount to validation.</p>
  
  <pre><code>def clean(self):
      super(ArticleForm, self).clean()
      **check whether user has posted recently, if so, raise ValidationError**
      return self.cleaned_data
  </code></pre>
  
  <p>J</p>