title: Django edit form based on add form?
body: <p>I've made a nice form, and a big complicated 'add' function for handling it. It starts like this...</p>
  
  <pre><code>def add(req):
      if req.method == 'POST':
          form = ArticleForm(req.POST)
          if form.is_valid():
              article = form.save(commit=False)
              article.author = req.user
              # more processing ...
  </code></pre>
  
  <p>Now I don't really want to duplicate all that functionality in the <code>edit()</code> method, so I figured <code>edit</code> could use the exact same template, and maybe just add an <code>id</code> field to the form so the <code>add</code> function knew what it was editing. But there's a couple problems with this</p>
  
  <ol>
  <li>Where would I set <code>article.id</code> in the <code>add</code> func? It would have to be after <code>form.save</code> because that's where the article gets created, but it would never even reach that, because the form is invalid due to unique constraints (unless the user edited everything). I can just remove the <code>is_valid</code> check, but then <code>form.save</code> fails instead.</li>
  <li>If the form actually <em>is</em> invalid, the field I dynamically added in the edit function isn't preserved.</li>
  </ol>
  
  <p>So how do I deal with this?</p>