Cool, it works now! Thanks a lot!

Cheers!

On Jul 17, 9:59 pm, "mr.freeze" <nat...@freezable.com> wrote:
> Try moving the requires after the define_table. I believe it is trying
> to reference poll before it is created.
>
> db.define_table('poll',
>                 Field('question', 'text', length=120, ),
>                 Field('author', db.auth_user, default=user_id,
> readable=False,writable=False))
>
> db.poll.question.requires=[IS_NOT_EMPTY(),
>                            IS_NOT_IN_DB(db(db.poll.author ==
> user_id),
>                                         'poll.question',
>                                          error_message = 'Question
> already existed!')]
>
> On Jul 17, 2:30 pm, Zhe Li <linuxcity...@gmail.com> wrote:
>
>
>
> > Hi Mr.Freeze,
>
> > It said KeyError: 'poll',
>
> > Error traceback
> > Traceback (most recent call last):
> >   File "/Users/zheli/Development/workspace/zenmezheng/web2py/gluon/
> > restricted.py", line 178, in restricted
> >     exec ccode in environment
> >   File "/Users/zheli/Development/workspace/zenmezheng/web2py/
> > applications/init/models/db.py", line 85, in <module>
> >     IS_NOT_IN_DB(db(db.poll.author == user_id), 'poll.question')],
> >   File "/Users/zheli/Development/workspace/zenmezheng/web2py/gluon/
> > sql.py", line 1329, in __getattr__
> >     return dict.__getitem__(self,key)
> > KeyError: 'poll'
>
> > also in db.py I assigned user_id as auth.user.id:
> > if auth.is_logged_in():
> >     user_id = auth.user.id
> > else:
> >     user_id = None
>
> > Thanks
> > Zhe
>
> > On Jul 17, 9:03 pm, "mr.freeze" <nat...@freezable.com> wrote:
>
> > > What does the error say?
>
> > > On Jul 17, 1:47 pm, Zhe Li <linuxcity...@gmail.com> wrote:
>
> > > > Hello everyone,
>
> > > > I was trying to do a validation in db.py like:
>
> > > > db.define_table('poll',
> > > > SQLField('question', 'text', requires=[IS_NOT_EMPTY(),
> > > > IS_NOT_IN_DB(db(db.poll.author == user_id), 'poll.question',
> > > > error_message = 'Question already existed!')], length=120)
> > > > SQLField('author', db.auth_user, default=user_id, readable=False,
> > > > writable=False))
>
> > > > but instead of checking if the same guy has post the same question, it
> > > > gives me an error. Is there anything wrong with my code? Many thanks!!
>
> > > > Cheers,
> > > > Zhe

Reply via email to