I am struggling to work out the right solution for what I am trying to do here, and I will be very grateful for the help.
Right now I have a working system that takes "Special" from db and displays it in a browser. The user can edit this "Special" in the browser and send it to db. This change is displayed to the user.
The problem is that "Special" will not be updated if a pre-existing "Special" does not exist in db. In my views.py, I have:
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')
I know that the reason why the Special update does not work is because it get_object_or_404correctly returns a 404 error, since there is no previously existing Special in db.
- , , db "Special" .
get_object_or_404 try except, , 'unicode' has no attribute 'save()'.