[web2py] Re: Model with 2 fields were one field is required

2011-02-08 Thread grezly
Thanks Massimo,

The fieldnames are arbitrary, i indeed use different names for it (not
even start(_time) or end(_time) )
What i indeed needed was the onvalidation for a crud.

Cheers

On Feb 7, 3:43 pm, Massimo Di Pierro 
wrote:
> first of all start and end and sql keywords you should choose another
> name.
>
> I suggest
>
> db.define_table('event',Field('title'),Field('start_time'),Field('end_time'))
>
> def exclusive(form):
>     if form.vars.start_time and form.vars.end_time:
>         form.errors.end_time = 'you already filled start time')
>     elif not form.vars.start_time and not form.vars.end_time:
>         form.errors.estart_time = 'you must fill start time or end
> time')
>
> then use
> form = crud.create(db.event,onvalidation=exclusive)
> and/or
> form = crud.update(db.event,id,onvalidation=exclusive)
>
> On Feb 7, 6:57 am, grezly  wrote:
>
> > i have a table with 3 fields:
>
> > title
> > start
> > end
>
> > For some reason i want to have the following; the title has to be
> > filled in always, but for the start and end field belongs a rule to
> > the fields; only 1 of the two fields can be filledin, They also can't
> > be either empty or filled in.
>
> > It's up to the user which one of the 2 fields he wants to fill in,
> > none of them is more important than the other.


[web2py] Re: Model with 2 fields were one field is required

2011-02-07 Thread Massimo Di Pierro
first of all start and end and sql keywords you should choose another
name.

I suggest

db.define_table('event',Field('title'),Field('start_time'),Field('end_time'))

def exclusive(form):
if form.vars.start_time and form.vars.end_time:
form.errors.end_time = 'you already filled start time')
elif not form.vars.start_time and not form.vars.end_time:
form.errors.estart_time = 'you must fill start time or end
time')

then use
form = crud.create(db.event,onvalidation=exclusive)
and/or
form = crud.update(db.event,id,onvalidation=exclusive)

On Feb 7, 6:57 am, grezly  wrote:
> i have a table with 3 fields:
>
> title
> start
> end
>
> For some reason i want to have the following; the title has to be
> filled in always, but for the start and end field belongs a rule to
> the fields; only 1 of the two fields can be filledin, They also can't
> be either empty or filled in.
>
> It's up to the user which one of the 2 fields he wants to fill in,
> none of them is more important than the other.