Re: [web2py] Re: Many-to-many admin form
OK thanks, I will take a look through the resources you have provided. -- Regards, Bruce On Wed, Dec 28, 2011 at 12:35 PM, Christopher Steel chris.st...@gmail.comwrote: OK, Here are some resources you will want to check out if you have not found them on your own already. # Web2py Plugins ## http://web2py.com/plugins/default ### looks good http://web2py.com/plugins/default/tagging ### interesting http://web2py.com/plugins/default/multiselect http://web2py.com/plugins/default/dropdown # Powerform ## http://labs.blouweb.com/powerformwizard Multi table forms # http://dev.s-cubism.com/web2py_plugins ## Other the top functionality, slightly bleeding edge: http://dev.s-cubism.com/plugin_multiselect_widget http://dev.s-cubism.com/plugin_solidform -- -- Regards, Bruce Wade http://ca.linkedin.com/in/brucelwade http://www.wadecybertech.com http://www.warplydesigned.com http://www.fitnessfriendsfinder.com
Re: [web2py] Re: Many-to-many admin form
OK, If your database table is setup correctly then in the database examples section you should be able to create a form similar to the one in example 33 for a many to many relationship. http://web2py.com/examples/database_examples/buy ( http://web2py.com/examples/default/examples#database_examples see number 33 )
Re: [web2py] Re: Many-to-many admin form
I think what you mean to say is that you are are looking for the ability to make multiple selections in one or more tables using a single form that allows you create a user record. So for example a table of users, a table of email address types and a table of email addresses but the user on see a single form where they can enter their name and one or more email addresses and email address types. Does that sound about right? This is a bit different then a many-to-many database relationship. Actually in your form I do not see any things that appear to be what are commonly referred to as many-to-many relationships in database theory. Here is what Wikipedia has to say about database many-to-many relationships: http://en.wikipedia.org/wiki/Many-to-many_%28data_model%29 From my understanding in classic database theory we talk about many to many 'relationships' and the 'relationships are recorded to a third table. The tables to the left and right of the relationship table both have what resembles a many to one relationship with the middle table but they have a many to many relationship with one another. The relationship table is what allows for the many to many relationship. For example: table one = products table two = purchases table three = buyers or products -- purchases -- buyers so if products contains soap and john buys some soap then we have the following entry in the purchases table: john, soap but we could also have jill, shoes jill, soap and so on
Re: [web2py] Re: Many-to-many admin form
Hi Christopher, * * *That is pretty much what I am after.* * * *table = keywords values ('Art', 'Games', 'Money') # Used to find all ads related based on keywords they select* *table = ad (* * url,* * created_by* * keywords - can have 0 or more keywords, keywords can belong to 0 or more ad's* *)* *table = ad_keyword value (ad.id = 1, keyword.id = 1) etc...* * * *form:* *url* *created_by = logged in member* *keywords = shows a list of existing keywords, or uses auto completion, [can select 0 or more and create a new keyword if not exist] if the keyword does not exist it is inserted (only inserted as a new keyword not linked to * *this ad until the ad is saved). **you then save the ad, and add the record to ad_keyword table* * * *If the above is still not clear let me know and I will try to figure out a different way to explain it. If I can't think of a better way to explain I will just write working code and provide it once it is done :)* * * *--* *Regards,* *Bruce* * * On Sun, Dec 25, 2011 at 11:11 PM, Christopher Steel chris.st...@gmail.comwrote: I think what you mean to say is that you are are looking for the ability to make multiple selections in one or more tables using a single form that allows you create a user record. So for example a table of users, a table of email address types and a table of email addresses but the user on see a single form where they can enter their name and one or more email addresses and email address types. Does that sound about right? This is a bit different then a many-to-many database relationship. Actually in your form I do not see any things that appear to be what are commonly referred to as many-to-many relationships in database theory. Here is what Wikipedia has to say about database many-to-many relationships: http://en.wikipedia.org/wiki/Many-to-many_%28data_model%29 From my understanding in classic database theory we talk about many to many 'relationships' and the 'relationships are recorded to a third table. The tables to the left and right of the relationship table both have what resembles a many to one relationship with the middle table but they have a many to many relationship with one another. The relationship table is what allows for the many to many relationship. For example: table one = products table two = purchases table three = buyers or products -- purchases -- buyers so if products contains soap and john buys some soap then we have the following entry in the purchases table: john, soap but we could also have jill, shoes jill, soap and so on -- -- Regards, Bruce Wade http://ca.linkedin.com/in/brucelwade http://www.wadecybertech.com http://www.warplydesigned.com http://www.fitnessfriendsfinder.com
Re: [web2py] Re: Many-to-many admin form
I looked at the examples they seem to just show how to link at the database level. From my example code I already have that part working. It is at the form/view level I am looking at adding functionality. On Sat, Dec 24, 2011 at 9:41 AM, Christopher Steel chris.st...@gmail.comwrote: For an example of a Web2py database with a many to many relationship you can see example number 29 under the database examples section: http://web2py.com/examples/default/examples Go to the section called Database Examples See the first example -- -- Regards, Bruce Wade http://ca.linkedin.com/in/brucelwade http://www.wadecybertech.com http://www.warplydesigned.com http://www.fitnessfriendsfinder.com
Re: [web2py] Re: Many-to-many admin form
The web2py admin works diferently to the django admin. The web2py admin is for install apps and manage instances. 2011/12/23 Bruce Wade bruce.w...@gmail.com I am guessing from the lack of responses this is not possible with Web2py's current admin? On Wed, Dec 21, 2011 at 4:49 PM, Bruce Wade bruce.w...@gmail.com wrote: Hello, I know django has this ability so I am assuming web2py also does. (Here is to hoping :D) First the models: db.define_table('adreports', Field('reporttype', unique=True) ) db.define_table('ads', Field('member_id', db.auth_user, default=auth.user_id), Field('points', 'integer', default=0), Field('url'), Field('language'), Field('location'), Field('accepted', 'boolean', default=False), Field('viewable', 'boolean'), Field('updated_at','datetime', default=request.now), Field('added_at','datetime', default=request.now) ) db.define_table('keywords', Field('isapproved', 'boolean', default=False), Field('key') ) db.define_table('ad_report', Field('ad_id', db.ads), Field('reportad_id', db.adreports) ) db.define_table('ad_keyword', Field('ad_id', db.ads), Field('keyword_id', db.keywords) ) db.ads.url.requires = (IS_URL(), IS_NOT_IN_DB(db, db.ads.url)) db.ad_report.ad_id.requires = IS_IN_DB(db, db.ads.id, %(url)s) db.ad_report.reportad_id.requires = IS_IN_DB(db, db.adreports.id, %(reporttype)s) db.ad_keyword.ad_id.requires = IS_IN_DB(db, db.ads.id, %(url)s) db.ad_keyword.keyword_id.requires = IS_IN_DB(db, db.keywords.id, %(key)s) -- Now I would like to be able, from the admin create a new ad and on the same page add multiple keywords and/or reports for the ad. This would have to happen with creating a new ad as well as when editing an existing ad. With Django you use: admin.TabularInline and inlines on admin.ModelAdmin classes https://docs.djangoproject.com/en/dev/ref/contrib/admin/#inlinemodeladmin-objects Has something similar being developed for web2py admin application? -- Regards, Bruce Wade http://ca.linkedin.com/in/brucelwade http://www.wadecybertech.com http://www.warplydesigned.com http://www.fitnessfriendsfinder.com -- -- Regards, Bruce Wade http://ca.linkedin.com/in/brucelwade http://www.wadecybertech.com http://www.warplydesigned.com http://www.fitnessfriendsfinder.com -- Alvaro Lizama Molina - http://alvarolizama.net
Re: [web2py] Re: Many-to-many admin form
I understand that, but you can also use the database portion to create new data. That is mainly the part I am talking about. When clicking database then insert in a table, it would be nice if the relationships could be linked on that insert. This would make performing inserts more efficiently. Anyway which files should I start looking at to see how I can implement this functionality for myself and anyone else who wants it? Best Regards, Bruce On Fri, Dec 23, 2011 at 7:05 AM, Alvaro Lizama Molina nek...@gmail.comwrote: The web2py admin works diferently to the django admin. The web2py admin is for install apps and manage instances. 2011/12/23 Bruce Wade bruce.w...@gmail.com I am guessing from the lack of responses this is not possible with Web2py's current admin? On Wed, Dec 21, 2011 at 4:49 PM, Bruce Wade bruce.w...@gmail.com wrote: Hello, I know django has this ability so I am assuming web2py also does. (Here is to hoping :D) First the models: db.define_table('adreports', Field('reporttype', unique=True) ) db.define_table('ads', Field('member_id', db.auth_user, default=auth.user_id), Field('points', 'integer', default=0), Field('url'), Field('language'), Field('location'), Field('accepted', 'boolean', default=False), Field('viewable', 'boolean'), Field('updated_at','datetime', default=request.now), Field('added_at','datetime', default=request.now) ) db.define_table('keywords', Field('isapproved', 'boolean', default=False), Field('key') ) db.define_table('ad_report', Field('ad_id', db.ads), Field('reportad_id', db.adreports) ) db.define_table('ad_keyword', Field('ad_id', db.ads), Field('keyword_id', db.keywords) ) db.ads.url.requires = (IS_URL(), IS_NOT_IN_DB(db, db.ads.url)) db.ad_report.ad_id.requires = IS_IN_DB(db, db.ads.id, %(url)s) db.ad_report.reportad_id.requires = IS_IN_DB(db, db.adreports.id, %(reporttype)s) db.ad_keyword.ad_id.requires = IS_IN_DB(db, db.ads.id, %(url)s) db.ad_keyword.keyword_id.requires = IS_IN_DB(db, db.keywords.id, %(key)s) -- Now I would like to be able, from the admin create a new ad and on the same page add multiple keywords and/or reports for the ad. This would have to happen with creating a new ad as well as when editing an existing ad. With Django you use: admin.TabularInline and inlines on admin.ModelAdmin classes https://docs.djangoproject.com/en/dev/ref/contrib/admin/#inlinemodeladmin-objects Has something similar being developed for web2py admin application? -- Regards, Bruce Wade http://ca.linkedin.com/in/brucelwade http://www.wadecybertech.com http://www.warplydesigned.com http://www.fitnessfriendsfinder.com -- -- Regards, Bruce Wade http://ca.linkedin.com/in/brucelwade http://www.wadecybertech.com http://www.warplydesigned.com http://www.fitnessfriendsfinder.com -- Alvaro Lizama Molina - http://alvarolizama.net -- -- Regards, Bruce Wade http://ca.linkedin.com/in/brucelwade http://www.wadecybertech.com http://www.warplydesigned.com http://www.fitnessfriendsfinder.com
Re: [web2py] Re: Many-to-many admin form
I have solved these kinds of concerns with pyramid based applications using sqlalchemy. However I need to look into the core of how Web2py handles things to figure out the best way. Sqlachemy allows you to put everything in: 1) Transactions 2) Sessions So on submit you first create the parent record: ad = Ad() session.add(ad) session.flush() Now you have access to ad.id (parent id) report = Report(...) report.ad_id = ad.id session.add(report) Now if you used Sqlachemy relationships ad.reports.append(report) # use this instead of report.ad_id = ad.id session.flush() Or in the case of having multiple children created before creating the parent on a web form. You just submit all the form data at once and loop through all reports. ad = Ad(...) session.add(ad) session.flush() get list of all reports in form submit for report in reports: session.add(report) ad.reports.append(report) session.flush() If anything fails the transaction automatically roles everything back. Or a easier solution is to only enable the children on edits. So you first create the parent, then you can view/edit/delete children on the parent edit page. -- Regards, Bruce On Fri, Dec 23, 2011 at 10:00 AM, Cliff cjk...@gmail.com wrote: Bruce, you are more brave than me ;) I always like to get the parent record committed in the database before adding child records. that way you know the ID of the parent record and it has the minimal required fieldset safely saved away. If there's a session interruption you don't have some potential orphan child records floating around somewhere. If you've solved those kinds of concerns, please share it with us. Thanks, Cliff Kachinske On Dec 23, 10:34 am, DenesL denes1...@yahoo.ca wrote: On Dec 23, 10:11 am, Bruce Wade bruce.w...@gmail.com wrote: Anyway which files should I start looking at to see how I can implement this functionality for myself and anyone else who wants it? Look for controller appadmin under your or any other app folder. -- -- Regards, Bruce Wade http://ca.linkedin.com/in/brucelwade http://www.wadecybertech.com http://www.warplydesigned.com http://www.fitnessfriendsfinder.com
Re: [web2py] Re: Many-to-many admin form
web2py wraps each request in a single transaction by default, so if you make multiple inserts during a request and the request ultimately fails due to an error, the inserts should be rolled back automatically. See http://web2py.com/books/default/chapter/29/4#Workflow and http://web2py.com/books/default/chapter/29/6#commit-and-rollback. Anthony On Friday, December 23, 2011 1:22:34 PM UTC-5, Detectedstealth wrote: I have solved these kinds of concerns with pyramid based applications using sqlalchemy. However I need to look into the core of how Web2py handles things to figure out the best way. Sqlachemy allows you to put everything in: 1) Transactions 2) Sessions So on submit you first create the parent record: ad = Ad() session.add(ad) session.flush() Now you have access to ad.id (parent id) report = Report(...) report.ad_id = ad.id session.add(report) Now if you used Sqlachemy relationships ad.reports.append(report) # use this instead of report.ad_id = ad.id session.flush() Or in the case of having multiple children created before creating the parent on a web form. You just submit all the form data at once and loop through all reports. ad = Ad(...) session.add(ad) session.flush() get list of all reports in form submit for report in reports: session.add(report) ad.reports.append(report) session.flush() If anything fails the transaction automatically roles everything back. Or a easier solution is to only enable the children on edits. So you first create the parent, then you can view/edit/delete children on the parent edit page. -- Regards, Bruce On Fri, Dec 23, 2011 at 10:00 AM, Cliff cjk...@gmail.com wrote: Bruce, you are more brave than me ;) I always like to get the parent record committed in the database before adding child records. that way you know the ID of the parent record and it has the minimal required fieldset safely saved away. If there's a session interruption you don't have some potential orphan child records floating around somewhere. If you've solved those kinds of concerns, please share it with us. Thanks, Cliff Kachinske On Dec 23, 10:34 am, DenesL dene...@yahoo.ca wrote: On Dec 23, 10:11 am, Bruce Wade bruce...@gmail.com wrote: Anyway which files should I start looking at to see how I can implement this functionality for myself and anyone else who wants it? Look for controller appadmin under your or any other app folder. -- -- Regards, Bruce Wade http://ca.linkedin.com/in/brucelwade http://www.wadecybertech.com http://www.warplydesigned.com http://www.fitnessfriendsfinder.com