I think the solution is use the third table "article_author" with
both, author_id and article_id having an autocomplete widget. Then,
add a button there to [create author if not exist][1].

I think all this can be performed in a [single form][2]

kind regards.

[1] http://www.web2pyslices.com/main/slices/take_slice/65
[2] http://www.web2pyslices.com/main/slices/take_slice/102

2011/2/4 Johann Spies <johann.sp...@gmail.com>:
> I would like to invite web2py users who enjoy such challenges to think with
> me about solving the following problem:
>
> Take two tables:
>
> db.define_table('article',
>                        Field("author_id", 'list:reference outeur'),
>                        Field("title"))
>
> db.define_table('author',
>                        Field('surname'),
>                        Field('initials'))
>
> Table 'article'  contains 137000 records and author about 108000.
>
> The field definition of 'author_id'  as list:reference would be ideal but in
> this case the list is too large and breaks javascript in the browser causing
> any crud.create or crud.update to take about 70 seconds to show the form.
>
> I am looking for a solution to be able to enter a new article while the same
> screen the user can either select an existing entry in 'author'  or add a
> new author linked to the article if the author does not exist in the
> database.  Keep in mind that one article can have several authors of which
> some may be in the database already and we try to avoid duplicate entries
> for the same author.
>
> Using an autocompletion widget for the author might have been useful if only
> one  author per article was allowed.
>
> One possible solution is to create a third table for many-to-many relations:
>
> db.define_table('author_article',
>                        Field('article_id', db.article,requires =
> IS_IN_DB(db,'article.id')),
>                        Field('author_id', db.author,requires =
> IS_IN_DB(db,'author.id')))
>
> In such a case how would one approach the entry forms in such a way that the
> user does not nead to choose different screens/menu options when the author
> is new or already in the database or when there are many authors for the
> same article?
>
> Regards
> Johann
>
>
> Regards
> Johann
> --
>  May grace and peace be yours in abundance through the full knowledge of God
> and of Jesus our Lord!  His divine power has given us everything we need for
> life and godliness through the full knowledge of the one who called us by
> his own glory and excellence.
>                                                     2 Pet. 1:2b,3a
>
>

Reply via email to