开发者

Django CheckboxSelectMultiple Data in View: BoundField Type Error

开发者 https://www.devze.com 2023-03-14 23:59 出处:网络
The error int() argument must be a string or 开发者_如何转开发a number, not \'BoundField\' My form is a multiplechoicefield

The error int() argument must be a string or 开发者_如何转开发a number, not 'BoundField'

My form is a multiplechoicefield

SKILLS = ((1, 'Fly'),(2,'Run'))
class Form(forms.Form):
    ability = forms.MultipleChoiceField(widget= forms.CheckboxSelectMultiple(), \
                                        choices = SKILLS, required=False)

now in my view i am trying to access each of the selcted data to perform a query

if "ability" in request.POST.keys():
    for ability in ability:
        x = ability
        sk = Skills.objects.get(id = x)

How can i fix this?


this is what you do:

if "ability" in request.POST.keys():
    for ability in ability:
        x = ability.value()
        sk = Skills.objects.get(id = x)

should work fine

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号