I have a model:
class Customer(models.Model):
name = models.CharField(max_length=200)
email = models.EmailField()
company = models.CharField(max_length=100, blank=True)
breakfast = models.BooleanField(blank=True)
dinner = models.BooleanField(blank=True)
training = models.BooleanField(blank=True)
joined = models.DateTimeField(auto_now_add=True)
And a view:
def cust_form(request):
if request.method == 'POST':
form = CustForm(request.POST)
form_type = 'Customer'
if form.is_valid():
email = request.POST['email']
name = request.POST['name']
if request.POST['training'] == True:
mail.mailsend(name, email, cus_type='train')
else:
mail.mailsend(name, email, cus_type='stand')
form.save()
return Redirect('/cr/')
return render_to_response('cust_form.html',
{'form': form,
'form_type': form_type},
context_instance=RequestContext(request))
I want to send one email if they’ve opted for training, and one if they have not. However, if the radio box is left unchecked, I get a MultiValueDictKeyError at /Customer/
Is the only solution to this a ForeignKey with yes/no?
You just need to check that the value is there.
or
(You shouldn’t compare against True, anyway.)