title: Django: how do i edit/update a model?
body: <p>Argh. Hey all, i have a muy simple django question:</p>
  
  <p>And argh, i'm sorry, i've read and read, and I am <em>sure</em> this is covered somewhere super-obviously, but i haven't found it!</p>
  
  <p>How do i edit/update a model using django? Like, the data values? Not the model fields?</p>
  
  <p>Here is my code! (I'm using a home-brew version of stuff!)</p>
  
  <p>Here is the urls:</p>
  
  <pre><code>url(r'^editStory/(?P&lt;id&gt;\d+)$',
      StoryModelView.as_view(
          context_object_name='form',
          template_name ='stories/editStory.html',
          success_template= 'stories/editStorySuccess.html'
      ),
      {},
      'editStory'
  ),
  </code></pre>
  
  <p>Here is the view:</p>
  
  <pre><code>def get(self,request,id=None):
      form = self.getForm(request,id)
      return self.renderValidations(form)
  
  def getForm(self, request,id):
      if id:
          return self.getModelById(request,id)
      return StoryForm()
  
  def getModelById(self,request,id):
      theStory = get_object_or_404(Story, pk=id)
      if theStory.user != request.user:
          raise HttpResponseForbidden()
      return StoryForm(theStory)
  
  def renderValidations(self,form):
      if self.context_object_name:
          contextName = self.context_object_name
      else:
          contextName = 'form'
      if self.template_name:
          return render_to_response(self.template_name,{contextName:form})
      else :
          return render_to_response('stories/addStory.html',{contextName:form})
  
  def getPostForm(self,request,id):
      if id:
          theStory = self.idHelper(request,id)
          return StoryForm(request.POST,theStory)
      return StoryForm(request.POST)
  
  def processForm(self,form,request):
      theStory = form.save(commit=False)
      theStory.user = request.user
      return theStory
  </code></pre>
  
  <p>Here is the template code:</p>
  
  <pre><code>{% block content %}
      &lt;h3&gt;Edit story&lt;/h3&gt;
      &lt;form action="" method="post"&gt;
          {%  csrf_token %}
          {%  for field in form %}
              &lt;div class="fieldWrapper"&gt;
                  {{ field.errors }}
                  {{ field.label_tag }} {{ field }}
              &lt;/div&gt;
          {% endfor %}
          &lt;input type="submit" value="Submit"/&gt;
      &lt;/form&gt;
  {% endblock %}
  </code></pre>
  
  <p>try as i might, i either:</p>
  
  <ol>
  <li>get an error</li>
  <li>get nothing</li>
  </ol>
  
  <p>i get an error with the code as-displayed, caused by this line</p>
  
  <blockquote>
  <pre><code>    {% for field in form %}
  </code></pre>
  </blockquote>
  
  <p>and with the error of:</p>
  
  <pre><code>Caught AttributeError while rendering: 'Story' object has no attribute 'get'
  </code></pre>
  
  <p>or i get nothing - no data at all - if i change my "getModelById" method to read:</p>
  
  <pre><code>def getModelById(self,request,id):
      theStory = get_object_or_404(StoryForm, pk=id)
      if theStory.user != request.user:
          raise HttpResponseForbidden()
      return theStory
  </code></pre>
  
  <p>StoryForm is one of those "ModelForm" things, and its model is "Story".</p>
  
  <p>SO! The question:</p>
  
  <p>how do i fix this code to make it work? What have i done wrong?</p>