-1

I'm trying to make it so that this email will send only if the boolean field is true. Unfortunately, I'm constantly getting invalid syntax errors.

in models.py

class PurchaseOrder(models.Model):
    has_responded = models.BooleanField(default = True)
    confirmed = models.NullBooleanField(null=True)

in views.py

def confirm(request, itemnum):
    item = get_object_or_404(PurchaseOrder, item_number = itemnum)
    item.confirmed = True
    item.save()
    confirm_title = 'Purchase Order %s Confirmed' % item.product
    send_mail(confirm_title, 'Check the Product Order System to see the updated list.', 'myemail@gmail.com',['youremail@gmail.com'], fail_silently=False)
    return HttpResponse('Product  %s  confirmed' % item.product )

I would like to make it where has_responded is defaulted to True. And then do an if statement where def confirm will only perform when has_responded is True. At the end of the def, I want to make has_responded to false. Therefore, it'll only perform once. unfortunately, I'm constantly getting errors and I have no idea why. The code above all works, but when I implement the if statement it just falls apart.

EDIT:

This is the code giving me the errors

  def confirm(request, itemnum):
     item = get_object_or_404(PurchaseOrder, item_number = itemnum)
     if item.has_responded == True
         item.confirmed = True
         item.save()
         confirm_title = 'Purchase Order %s Confirmed' % item.product
         send_mail(confirm_title, 'Check the Product Order System to see the updated list.', 'myemail@gmail.com',['youremail@gmail.com'], fail_silently=False)
         return HttpResponse('Product  %s  confirmed' % item.product )
         item.has_responded = False
4

1 回答 1

2

你忘记了:之后if item.has_responded == True。它应该是:

if item.has_responded == True:

您的代码中还有一些错误:

  1. 您需要在语句item.has_responded = False之前移动,return否则该行代码将不会执行
  2. 发送适当的HttpResponse时间item.has_responded = False
于 2013-08-06T21:29:46.023 回答