[web2py] Re: Problem with one-to-many field
I changed it back to Field('firma', db.firma) and now it works as expected. I really hope that it was somehow my mistake because I want to learn to use and trust web2py. Just for the record in case it happens to someone else: I had a foreign key (OneToMany relationship) that was not rendered as a select box in the database administration or on crud generated forms. This field was first added as a string field and then migrated to db.firma (foreign key), however the field rendering remained as textfield. I added some requirements hoping that it will help the database schema migration (as I learned the way that I added the requirements was FORCING the field to be a textfield: the opposite of my intention). When I change it back to the original form (Massiomo's suggestion) the problem was corrected. All the best, Radu On Jan 18, 4:39 pm, Massimo Di Pierro wrote: > Before you send me the app. Please explain again what is your model > now, what you get and what you expect. > > You original code was wrong because if the validator is a list than > there is no dropdown. That is not a bug but a feature. > > On Jan 18, 2:09 am, rif wrote: > > > > > > > > > It was Field('firma', db.firma), I added the requires parameter as a > > desperate measure thinking that it will trigger the right > > functionality. It really looks like a "glitch in the system". If it is > > useful to you I can send you the whole app. > > > Radu (from Romania :) > > > On Jan 17, 6:29 pm, Massimo Di Pierro > > wrote: > > > > Replace > > > > Field('firma', db.firma, requires=[IS_IN_DB(db, 'firma.id', '% > > > (nume)s')]), > > > > with > > > > Field('firma', db.firma, requires=IS_IN_DB(db, 'firma.id', '% > > > (nume)s')), > > > > or even better > > > > Field('firma', db.firma), > > > > the validator is automatic for reference fields. > > > > Field('firma', db.firma, requires=[IS_IN_DB(db, > > > 'firma.id', '%(nume)s')]), > > > > On Jan 17, 5:11 am, rif wrote: > > > > > Hi guys, > > > > > I just started working with web2py and I like it a lot. I have a > > > > little problem with the following tables: > > > > > The firma field in the second table is shown as a text field where I > > > > can only enter the ids and not as a select field. I admit that I might > > > > have saved the db.py with firma field as a string first but now the > > > > migration does not seem to take place. > > > > I have other foreign key fields that are working fine but this one is > > > > giving me troubles. Did I do something wrong here? > > > > > If you need more info please let me know. > > > > > Keep up the good work! > > > > Radu > > > > > db.define_table('firma', > > > > Field('nume', required=True, unique=True), > > > > format='%(nume)s' > > > > ) > > > > > db.define_table('angajat', > > > > Field('firma', db.firma, requires=[IS_IN_DB(db, > > > > 'firma.id', '%(nume)s')]), > > > > Field('nume', required=True), > > > > Field('prenume', required=True), > > > > Field('norma', 'integer', required=True, > > > > requires=[IS_INT_IN_RANGE(1,10)]), > > > > Field('activ', 'boolean', default=True), > > > > format='%(nume)s %(prenume)s' > > > > )
[web2py] Re: Problem with one-to-many field
Before you send me the app. Please explain again what is your model now, what you get and what you expect. You original code was wrong because if the validator is a list than there is no dropdown. That is not a bug but a feature. On Jan 18, 2:09 am, rif wrote: > It was Field('firma', db.firma), I added the requires parameter as a > desperate measure thinking that it will trigger the right > functionality. It really looks like a "glitch in the system". If it is > useful to you I can send you the whole app. > > Radu (from Romania :) > > On Jan 17, 6:29 pm, Massimo Di Pierro > wrote: > > > > > > > > > Replace > > > Field('firma', db.firma, requires=[IS_IN_DB(db, 'firma.id', '% > > (nume)s')]), > > > with > > > Field('firma', db.firma, requires=IS_IN_DB(db, 'firma.id', '% > > (nume)s')), > > > or even better > > > Field('firma', db.firma), > > > the validator is automatic for reference fields. > > > Field('firma', db.firma, requires=[IS_IN_DB(db, > > 'firma.id', '%(nume)s')]), > > > On Jan 17, 5:11 am, rif wrote: > > > > Hi guys, > > > > I just started working with web2py and I like it a lot. I have a > > > little problem with the following tables: > > > > The firma field in the second table is shown as a text field where I > > > can only enter the ids and not as a select field. I admit that I might > > > have saved the db.py with firma field as a string first but now the > > > migration does not seem to take place. > > > I have other foreign key fields that are working fine but this one is > > > giving me troubles. Did I do something wrong here? > > > > If you need more info please let me know. > > > > Keep up the good work! > > > Radu > > > > db.define_table('firma', > > > Field('nume', required=True, unique=True), > > > format='%(nume)s' > > > ) > > > > db.define_table('angajat', > > > Field('firma', db.firma, requires=[IS_IN_DB(db, > > > 'firma.id', '%(nume)s')]), > > > Field('nume', required=True), > > > Field('prenume', required=True), > > > Field('norma', 'integer', required=True, > > > requires=[IS_INT_IN_RANGE(1,10)]), > > > Field('activ', 'boolean', default=True), > > > format='%(nume)s %(prenume)s' > > > )
[web2py] Re: Problem with one-to-many field
It was Field('firma', db.firma), I added the requires parameter as a desperate measure thinking that it will trigger the right functionality. It really looks like a "glitch in the system". If it is useful to you I can send you the whole app. Radu (from Romania :) On Jan 17, 6:29 pm, Massimo Di Pierro wrote: > Replace > > Field('firma', db.firma, requires=[IS_IN_DB(db, 'firma.id', '% > (nume)s')]), > > with > > Field('firma', db.firma, requires=IS_IN_DB(db, 'firma.id', '% > (nume)s')), > > or even better > > Field('firma', db.firma), > > the validator is automatic for reference fields. > > Field('firma', db.firma, requires=[IS_IN_DB(db, > 'firma.id', '%(nume)s')]), > > On Jan 17, 5:11 am, rif wrote: > > > > > > > > > Hi guys, > > > I just started working with web2py and I like it a lot. I have a > > little problem with the following tables: > > > The firma field in the second table is shown as a text field where I > > can only enter the ids and not as a select field. I admit that I might > > have saved the db.py with firma field as a string first but now the > > migration does not seem to take place. > > I have other foreign key fields that are working fine but this one is > > giving me troubles. Did I do something wrong here? > > > If you need more info please let me know. > > > Keep up the good work! > > Radu > > > db.define_table('firma', > > Field('nume', required=True, unique=True), > > format='%(nume)s' > > ) > > > db.define_table('angajat', > > Field('firma', db.firma, requires=[IS_IN_DB(db, > > 'firma.id', '%(nume)s')]), > > Field('nume', required=True), > > Field('prenume', required=True), > > Field('norma', 'integer', required=True, > > requires=[IS_INT_IN_RANGE(1,10)]), > > Field('activ', 'boolean', default=True), > > format='%(nume)s %(prenume)s' > > )
[web2py] Re: Problem with one-to-many field
Replace Field('firma', db.firma, requires=[IS_IN_DB(db, 'firma.id', '% (nume)s')]), with Field('firma', db.firma, requires=IS_IN_DB(db, 'firma.id', '% (nume)s')), or even better Field('firma', db.firma), the validator is automatic for reference fields. Field('firma', db.firma, requires=[IS_IN_DB(db, 'firma.id', '%(nume)s')]), On Jan 17, 5:11 am, rif wrote: > Hi guys, > > I just started working with web2py and I like it a lot. I have a > little problem with the following tables: > > The firma field in the second table is shown as a text field where I > can only enter the ids and not as a select field. I admit that I might > have saved the db.py with firma field as a string first but now the > migration does not seem to take place. > I have other foreign key fields that are working fine but this one is > giving me troubles. Did I do something wrong here? > > If you need more info please let me know. > > Keep up the good work! > Radu > > db.define_table('firma', > Field('nume', required=True, unique=True), > format='%(nume)s' > ) > > db.define_table('angajat', > Field('firma', db.firma, requires=[IS_IN_DB(db, > 'firma.id', '%(nume)s')]), > Field('nume', required=True), > Field('prenume', required=True), > Field('norma', 'integer', required=True, > requires=[IS_INT_IN_RANGE(1,10)]), > Field('activ', 'boolean', default=True), > format='%(nume)s %(prenume)s' > )