Re: [web2py] Nested CRUD

2012-05-15 Thread Richard Vézina
Not sure, but SQLFORM.smartgrid don't do what you want?

Richard

On Tue, May 15, 2012 at 4:43 AM, Alec Taylor  wrote:

> Thanks Annet, that's what I currently have, but it doesn't allow for
> CRUD of anything but the outer table, it won't allow for CRUD of any
> of the inner tables.
>
> I would like—either in the drop down or as an "Add/modify" link next
> to it—the ability to CRUD entries in that referenced table.
>
> If there is an abstracted way of doing it, I would prefer that method
> rather than doing it manually, i.e.: inserting a link using
> form.element, then using the lazy_options_widget to update that field
> in the form
>
> So, is there one?
>
> On Tue, May 15, 2012 at 2:50 PM, Annet  wrote:
> >> So if I could generate one form that allows you to create a customer,
> >> complete with address, the management would become much more logical.
> >
> > In this case I'd use SQLFORM.factory:
> >
> > def create():
> > form=SQLFORM.factory(db.customer,db.address)
> > if form.process().accepted:
> > id = db.customer.insert(**db.customer._filter_fields(form.vars))
> > form.vars.customer=id
> > id = db.address.insert(**db.address._filter_fields(form.vars))
> > return dict(form=form)
> >
> > See the book:
> >
> http://www.web2py.com/books/default/chapter/29/7?search=insert%28**#One-form-for-multiple-tables
> >
> >
> > Regards Annet.
>


Re: [web2py] Nested CRUD

2012-05-15 Thread Alec Taylor
Thanks Annet, that's what I currently have, but it doesn't allow for
CRUD of anything but the outer table, it won't allow for CRUD of any
of the inner tables.

I would like—either in the drop down or as an "Add/modify" link next
to it—the ability to CRUD entries in that referenced table.

If there is an abstracted way of doing it, I would prefer that method
rather than doing it manually, i.e.: inserting a link using
form.element, then using the lazy_options_widget to update that field
in the form

So, is there one?

On Tue, May 15, 2012 at 2:50 PM, Annet  wrote:
>> So if I could generate one form that allows you to create a customer,
>> complete with address, the management would become much more logical.
>
> In this case I'd use SQLFORM.factory:
>
> def create():
> form=SQLFORM.factory(db.customer,db.address)
> if form.process().accepted:
> id = db.customer.insert(**db.customer._filter_fields(form.vars))
> form.vars.customer=id
> id = db.address.insert(**db.address._filter_fields(form.vars))
> return dict(form=form)
>
> See the book:
> http://www.web2py.com/books/default/chapter/29/7?search=insert%28**#One-form-for-multiple-tables
>
>
> Regards Annet.


Re: [web2py] Nested CRUD

2012-05-14 Thread Annet
> So if I could generate one form that allows you to create a customer, 
> complete with address, the management would become much more logical. 

In this case I'd use SQLFORM.factory:

def create():
form=SQLFORM.factory(db.customer,db.address)
if form.process().accepted:
id = db.customer.insert(**db.customer._filter_fields(form.vars))
form.vars.customer=id
id = db.address.insert(**db.address._filter_fields(form.vars))
return dict(form=form)

See the book: 
http://www.web2py.com/books/default/chapter/29/7?search=insert%28**#One-form-for-multiple-tables


Regards Annet.



Re: [web2py] Nested CRUD

2012-05-14 Thread Alec Taylor
Thanks, looks like this plugin will be helpful for that:
http://dev.s-cubism.com/plugin_lazy_options_widget

I'll find the book section and see what I can do.

On Tue, May 15, 2012 at 1:18 AM, Richard Vézina
 wrote:
> Think you should read the book section about more then one form per page and
> about component. What you want to do is hide a second form in the same
> page... Those form should be embeded in the page as component en then you
> have to write the proper logic in ajax and jQuery to make appears your
> second form when the first set of field have been completed...
>
> Also you can have a look at : http://dev.s-cubism.com/web2py_plugins
>
> Many fancy plugins for web2py that exist and make your life easier when you
> need it.
>
> Richard
>
> On Mon, May 14, 2012 at 10:42 AM, Alec Taylor 
> wrote:
>>
>> Is it possible to have a nested CRUD form?
>>
>> From a logical perspective it sometime doesn't make sense, for
>> example, to add an Address before you add a Customer.
>>
>> db.define_table('address',
>>    Field('line1','string', required=True),
>>    Field('line2','string'),
>>    Field('suburb','string', required=True),
>>    Field('post_code','integer'),
>>    Field('email','string')
>> )
>>
>> db.address.post_code.requires = IS_INT_IN_RANGE(, )
>> db.address.email.requires        = IS_EMAIL()
>>
>> db.define_table('customer',
>>    Field('name', 'string', required=True, unique=True),
>>    Field('locations', 'list:reference db.address', required=True),
>>    Field('comment', 'string')
>> ) # quick aside: how would I ensure there isn't another customer with
>> same name+location?
>>
>> db.address.requires = IS_IN_DB(db, db.address, '%(line1)s + ', " +
>> %(suburb)s', multiple=True)
>>
>> So if I could generate one form that allows you to create a customer,
>> complete with address, the management would become much more logical.
>>
>> How would I generate this?
>>
>> Thanks for all suggestions,
>>
>> Alec Taylor
>>
>> BTW: It would still be useful however to still be able to pick from
>> the list already in the db, but to just have an "Add" that will
>> rolldown with javascript, and which will open by default if that field
>> is empty (and .requires not to be).
>
>


Re: [web2py] Nested CRUD

2012-05-14 Thread Richard Vézina
Think you should read the book section about more then one form per page
and about component. What you want to do is hide a second form in the same
page... Those form should be embeded in the page as component en then you
have to write the proper logic in ajax and jQuery to make appears your
second form when the first set of field have been completed...

Also you can have a look at : http://dev.s-cubism.com/web2py_plugins

Many fancy plugins for web2py that exist and make your life easier when you
need it.

Richard

On Mon, May 14, 2012 at 10:42 AM, Alec Taylor wrote:

> Is it possible to have a nested CRUD form?
>
> From a logical perspective it sometime doesn't make sense, for
> example, to add an Address before you add a Customer.
>
> db.define_table('address',
>Field('line1','string', required=True),
>Field('line2','string'),
>Field('suburb','string', required=True),
>Field('post_code','integer'),
>Field('email','string')
> )
>
> db.address.post_code.requires = IS_INT_IN_RANGE(, )
> db.address.email.requires= IS_EMAIL()
>
> db.define_table('customer',
>Field('name', 'string', required=True, unique=True),
>Field('locations', 'list:reference db.address', required=True),
>Field('comment', 'string')
> ) # quick aside: how would I ensure there isn't another customer with
> same name+location?
>
> db.address.requires = IS_IN_DB(db, db.address, '%(line1)s + ', " +
> %(suburb)s', multiple=True)
>
> So if I could generate one form that allows you to create a customer,
> complete with address, the management would become much more logical.
>
> How would I generate this?
>
> Thanks for all suggestions,
>
> Alec Taylor
>
> BTW: It would still be useful however to still be able to pick from
> the list already in the db, but to just have an "Add" that will
> rolldown with javascript, and which will open by default if that field
> is empty (and .requires not to be).
>