Re: [web2py] Many-to-many relations with CRUD Insert

2012-01-17 Thread Christian Winterhager
I have also constraints on database level, but this is necessary for normal 
logical consistency of the database model. The problem is for me again - 
even if i use that "reference" or "list.reference" - that i cannot have *
ONLY* these fields

book.title
author.name

in my form on the screen and *only one submit-Button*, because CRUD accepts 
only one table and so there were 2 submit-buttons and 2 CRUD.create forms. 
As i said i want to insert the book-data (for simplicity here the title) 
without clicking the submit button, then select some author (better: one or 
more authors), then click submit, and the web2py-System must then insert 
the book, look for the new book-id and insert this book-id together with 
the author-id in the
connection-table "verb". On a very low-level programming view with CGI, 
Python and informix (or just MySQL) this can be done without
great effort, but you have to write too much code. That is the reason why i 
want to have a simple form, created by CRUD or SQLFORM. 

By the way, i searched the Newsgroup here and i did'nt find anyone, who had 
this same problem. I'm wondering about that, because it is a standard 
situation in many commercial databases: you have producers and articles, 
but the connection between the two ist stored in a new table- say 
"prod_art" in form of a tupel (producer_id, article_id). How to put 

Producer-, 
Article-Data and 
informations about who produces which article (Table "prod_art")

in only one FORM with only ONE Submit Button?

P.S. Naturally i have one solution, but i think it is a dirty one: 


   1. With CRUD make 2 INSERT-Forms for tables "author" and book.
   2. If FORM for the book is accepted, and we therefor know the new 
   book_id.
   3. go to the NEXTURL, i.e. the CRUD.create - FORM for the table "verb"
   4. In the Controller, before accepting the form, let verb.book_id = 
   book_id from step 2.
   5. Choose an author from the table "verb". Thanks to this CRUD-Feature!
   6. Insert verb.

Thats all, but it is too complicated for Users, wo want to insert thousends 
of Books: 2 Screen, 2 Submit-Buttons, switching

between the screens. As in said, i build a very user-friendly solution with 
CGI, but i think, it must be done also with web2py


Re: [web2py] Many-to-many relations with CRUD Insert

2012-01-17 Thread Johann Spies
On 17 January 2012 11:27, Johann Spies  wrote:

> I am working with a biliometric database
>

Sorry that must be bibliometric database
-- 
Because experiencing your loyal love is better than life itself,
my lips will praise you.  (Psalm 63:3)


Re: [web2py] Many-to-many relations with CRUD Insert

2012-01-17 Thread Johann Spies
On 17 January 2012 11:03, Christian Winterhager <
christian.winterha...@onlinehome.de> wrote:

> Yes, thats clear. Until now i use a program, which is based  on INFORMIXDB
> with Python und CGI. In this program (respectively programs) i do exactly
> that what you described above in your mail. It is not difficult to write
> these programs but it is slow and boring.
>
> But now i know web2py and i wanted to use this tool and all of its
> benefits to create more elegant forms and views. So my Question is again:
> Is there any method to create an INPUT-Form (not for output, SELECT is
> easy!) with CRUD or SQLFORM for the many-to-many Relation
> "book-author-verb"?
>
> Or more precisely: is it possible to make a form with CRUD or SQLFORM,
> which includes all fields of book and a listbox with autors, so that i can
> select one or more authors and then klick the *only *submit-button of the
> form to insert the book and the corresponding ids in table verb? I think
> the problem is that we have 2 tables for CRUD/SQLFORM, which are not
> directly connected via foreign keys (namely "book" and "author").
>

In the 'verb' table you can use the type 'reference'  for 'book'  and
'list:reference' for authors (with the multiple-option).  Then you can have
a form using crud for input where you can select the book and the list of
authors.

See http://www.web2py.com/books/default/chapter/29/6?search=list%3Areference
.

I am working with a biliometric database and I have inserted constraints on
database level to prevent the same combination of appearing in the linking
table ('verb' in your case). I am working with Postgresql and found that
the web2py-communications with the database breaks when this constraint
complains.  So I had to build in code to check for the existence of that
combination of fields in the table before inserting it.

Regards
Johann



-- 
Because experiencing your loyal love is better than life itself,
my lips will praise you.  (Psalm 63:3)


Re: [web2py] Many-to-many relations with CRUD Insert

2012-01-17 Thread Christian Winterhager
Yes, thats clear. Until now i use a program, which is based  on INFORMIXDB 
with Python und CGI. In this program (respectively programs) i do exactly 
that what you described above in your mail. It is not difficult to write 
these programs but it is slow and boring.

But now i know web2py and i wanted to use this tool and all of its benefits 
to create more elegant forms and views. So my Question is again: Is there 
any method to create an INPUT-Form (not for output, SELECT is easy!) with 
CRUD or SQLFORM for the many-to-many Relation "book-author-verb"?  

Or more precisely: is it possible to make a form with CRUD or SQLFORM, 
which includes all fields of book and a listbox with autors, so that i can 
select one or more authors and then klick the *only *submit-button of the 
form to insert the book and the corresponding ids in table verb? I think 
the problem is that we have 2 tables for CRUD/SQLFORM, which are not 
directly connected via foreign keys (namely "book" and "author").


Re: [web2py] Many-to-many relations with CRUD Insert

2012-01-16 Thread Johann Spies
On 16 January 2012 22:35, Christian Winterhager <
christian.winterha...@onlinehome.de> wrote:

> One of the standard examples  of many-to-many Relations is a library. For
> simplicity i choose only 3 Tables:
>
> db.define_table ('author',
> Field ('name', 'string', length=100))
>
> db.define_table ('verb',
>Field ('bnr', db.book ),
>Field ('anr', db.author ),
> )
>
> db.define_table ('book',
> Field('title', 'string', length=250))
>
> It is very easy to insert a new book, one or more author and the
> corresponding record
> in the table "verb". But i found no way to insert a book with the
> CRUD-Method. The 
> complexity
> is that i first must insert a row into  table "book", then one into table
> "author" and last i have to connect
> the inserted rows with the corresponding numbers 'bnr' and 'anr' in table
> "verb". Does anyone know if there
> is a way to do that with CRUD?
>

I don't think you can do this in one step.

I would do the following:

1. Find the author in the author table and if it is not there, insert.  For
each author, collect the id of the record.
2. Then insert the book and get the id
3. Then for each author create a record in 'verb'. I would do this in the
background without any form involved.

Regards
Johann



-- 
Because experiencing your loyal love is better than life itself,
my lips will praise you.  (Psalm 63:3)


[web2py] Many-to-many relations with CRUD Insert

2012-01-16 Thread Christian Winterhager
One of the standard examples  of many-to-many Relations is a library. For 
simplicity i choose only 3 Tables:

db.define_table ('author',
Field ('name', 'string', length=100))

db.define_table ('verb',
   Field ('bnr', db.book ),  
   Field ('anr', db.author ), 
)

db.define_table ('book',
Field('title', 'string', length=250))

It is very easy to insert a new book, one or more author and the 
corresponding record
in the table "verb". But i found no way to insert a book with the 
CRUD-Method. The 
complexity
is that i first must insert a row into  table "book", then one into table 
"author" and last i have to connect
the inserted rows with the corresponding numbers 'bnr' and 'anr' in table 
"verb". Does anyone know if there
is a way to do that with CRUD?