开发者

Python pyramid_simpleform how do I deal with relationships?

I'm moving my first steps with pyramid_simpleform after having ever used formalchemy in Pylons 1.

The form I'm starting with is pretty simple: I have some options and user has to check one开发者_运维知识库.

here the form class:

class OptionsSchema(Schema):
    ...
    id_opt = validators.Int(not_empty=True)

here it's instance in view:

model = DBSession.query(models.Model).first()
form = Form(request, schema=OptionsSchema, obj=model)
renderer = FormRenderer(form)

let's say model.id_opt == 3,

here I make a radio button for each option in model in template:

%for opt in model.options:
    ${form.radio('id_opt', value=opt.id)}
%endfor

what I expected to see was a checked="checked" for id_opt == 3like this:

<input id="id_opt_1" name="id_opt" type="radio" value="1" />    
<input id="id_opt_2" name="id_opt" type="radio" value="2" />    
<input id="id_opt_3" checked="checked" name="id_opt" type="radio" value="3" />    

but I get none.

Must I set checked option by myself?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜