2011-10-08 4 views
1

web2py에서 설문 조사 응용 프로그램을 만들려고합니다.web2py 양식의 여러 인스턴스

모델

db.define_table('t_query', 
    Field('f_content', type='text', requires=IS_NOT_EMPTY(), 
      label=T('Content')), 
    SQLField('is_active',db.auth_user,writable=False,readable=False), 
    auth.signature, 
    migrate=settings.migrate) 

db.define_table('t_option', 
    Field('f_ocontent', type='string',requires=IS_NOT_EMPTY(), 
      label=T('Option')), 
    auth.signature, 
    migrate=settings.migrate) 

컨트롤러

def ask(): 
    form=SQLFORM.factory(db.t_query,db.t_option,db.t_option) 
    if form.process().accepted: 
     id = db.t_query.insert(**db.t_query._filter_fields(form.vars)) 
     form.vars.client=id 
     id = db.t_option.insert(**db.t_option._filter_fields(form.vars)) 
     response.flash='Thanks for filling the form' 
     id = db.t_option.insert(**db.t_option._filter_fields(form.vars)) 
     response.flash='Thanks for the question' 
    return dict(form=form) 

보기

{{extend 'layout.html'}} 

<h2>Start a Poll</h2> 
{{=form}} 

출력
current

나는 형태로 같은 테이블에서 여러 번 필드를 사용 SQLFORM을 요청하는 방법을 찾는 노력했다.

이 내가 기대하는 것입니다 : 나는 그것에 대해 어떻게 가야합니까
gexpectation

? web2py @ 당신이 하나의 필드에 대한 문자열 목록을 저장할 수 있도록하려는 것 소리 https://groups.google.com/forum/#!topic/web2py/48tO5ncC2t4

+2

btw, 당신은 두 개의'response.flash' 할당을 볼 수 있습니다. 두 번째는 첫 번째 메시지를 덮어 씁니다. if 문이 없으면 하나의 플래시 메시지를 보낼 때와 다른 메시지를 보낼 때를 결정할 때마다 양식이 성공적으로 처리됩니다. 어쩌면 현재 코드에는 문제가되지 않을 수도 있습니다. 지적하다. – Kasapo

답변

1

을 구글 그룹스에

같은 질문을 물었다. 지금까지 내가 아는 한 여러 번 동일한 필드를 반복 할 수는 없습니다 (데이터가 데이터베이스에 저장되는 위치는 어디일까요?이 필드를 포함 할 수있는 필드가 하나뿐이므로 0을 원한다면 직렬화하고 잼해야합니다).

|option1val|option2val|option3val| 

또는 비어있는 경우 :

db.define_table(... 
    ... 
    Field('f_ocontent', 'list:string') 
) 

이 같은 내부적으로 데이터를 저장할 : 단일 필드에 .N 값)

사용이 하나의 필드에 여러 개의 문자열을 얻을 수 있습니다 :

|| 

문자가 0 개 이상인 입력에있을 때 입력을 누르면 새로운 입력이 생성됩니다.