title: Django: get_object_or_404 not the right solution, but what is?
body: <p>I'm struggling to work out the correct solution for what I'm trying to do here and would really appreciate some help.</p>
  
  <p>At the moment, I have a working system which takes a "Special" from the db and displays it in the browser. The user is able to edit that "Special" in the browser and submit it to the db. That change is then shown to the user.</p>
  
  <p>The problem is that the "Special" will not update if there is no pre-existing "Special" in the db. In my views.py I have:</p>
  
  <pre><code>def changeSpecialOffer(theRequest):
      myProductUuid = theRequest.POST['myProductUuid']
      myNewSpecialOffer = theRequest.POST['myNewSpecialOffer']
      myProduct = get_object_or_404(Product, uuid=myProductUuid)
      myActiveSpecial = get_object_or_404(SpecialOffer.objects.filter(product=myProduct).filter(
                                                              active=True))
      try:
          myActiveSpecial.special = myNewSpecialOffer
          myActiveSpecial.save()
      except:
          return HttpResponse(myActiveSpecial, mimetype='text/plain')
      myActiveSpecial = SpecialOffer.objects.filter(product=myProduct).filter(
                                                              active=True)
      return HttpResponse(myActiveSpecial, mimetype='text/plain')
  </code></pre>
  
  <p>I know that the reason the updating of the "Special" does not work is because the <code>get_object_or_404</code> is correctly returning a 404 error as there is no pre-existing "Special" in the db.</p>
  
  <p>I've been trying for a while to work out the best way to get around this problem without breaking the function in cases where there is an existing "Special" in the db.</p>
  
  <p>So far, I've tried replacing the <code>get_object_or_404</code> with <code>try</code> and <code>except</code>, but I then run into problems with the save function, such as <code>'unicode' has no attribute 'save()'</code>.</p>