I have the following:
Models.Py
class MyModel(models.Model):
user = models.ForeignKey(User, max_length=40, blank=False)
name = models.ForeignKey(Currencies, max_length=40, blank=False)
checkbox = models.BooleanField(default=False)
def __unicode__(self):
return self.name
Forms.py
class MyForm(forms.ModelForm):
class Meta:
model = MyModel
fields = (['Name', 'Checkbox'])
Views.py
def test(request):
if request.method == "POST":
form = MyForm(request.POST)
if form.is_valid():
post = form.save(commit=False)
post.user = request.user
post.save()
return True
else:
form = AuctionForm()
return render(request, 'test.html', {'form': form})
This works fine, and shows me a nice form in test.html to fill in. However, once I click the save button two things happen:
1) I get redirected to debug, where I see the following error.
Django Version: 1.8
Exception Type: AttributeError
Exception Value:
'bool' object has no attribute 'get'
2) My model gets updated and the information does show.
What am I doing wrong here?
Bool object has no attribute 'get'?
Is that my checkbox?
You can't return True
in your views method. Views method must either return HttpResponse
or better, redirect to some other views using redirect.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With