>I don't understand what you try to do... You mean you have to show all >the >fields? 1. No, I pick some of fields I need from existing table by specifying at model 2. Create/Edit form, I want user to edit some of them but the others should be readonly
This will cause error... >From your suggestion, I confirmed it's working fine if I create the table with id w/auto increment. Fortunately, my current project allow me to create one. So I will go with this. I will submit a bug report for this. On Nov 1, 3:05 pm, Richard Vézina <[email protected]> wrote: > I don't understand what you try to do... You mean you have to show all the > fields? > > You can just don't tell web2py the field you don't want to show... Just > omit them in your model definition?! > > Since you only read or select your are not don't need writable=false... > > Maybe you don't use the proper tool... SQLFORM is maybe not what you want > to use, or you should have an other look at the doc and pay attention to > the detail about how to use it to mimic the crud.something behavior. We are > supposed to be able to do the exact samething with SQLFORM that we do with > crud and much more... But you can start with crud. There is also > SQLFORM.factory and you can even build your own form with helpers... > > Richard > > On Tue, Nov 1, 2011 at 3:33 PM, Omi Chiba <[email protected]> wrote: > > Richard, > > > Thank you for you suggestion ! > > > >Field('legacy_id_field_name','id'), > > I tried this but the same result. > > > > sequence_name='name_of_sequence_in_legacy_database' > > Not sure about it, especially I dont' use any auto increment... > > Yes you don't need this... > > > > > > > > > This problem is critical like I need to suspend my project. Right now > > I only have choice to display all the fields with writable=True, or > > read only.... This is nightmare. > > > On Nov 1, 2:09 pm, Richard Vézina <[email protected]> wrote: > > > At least if your DB2 is a legacy database you maybe need to define you id > > > field like this : > > > > Field('legacy_id_field_name','id'), > > > > I think it is a not documented functionality offer to postgres user that > > > can maybe apply to your situation... > > > > There is also this : > > > > sequence_name='name_of_sequence_in_legacy_database' > > > > Also to solve postgres users problem with sequence created by postgres > > that > > > follow a strict pattern... When you create your table with web2py there > > is > > > no problem it handle the name of the sequence... > > > > Maybe it could apply and help to solve your problem. > > > > Richard > > > > On Tue, Nov 1, 2011 at 3:02 PM, Richard Vézina > > > <[email protected]>wrote: > > > > > Hello Omi, > > > > > Is this problem have been resolved with the other thread? > > > > > Richard > > > > > On Tue, Nov 1, 2011 at 12:53 PM, Omi Chiba <[email protected]> wrote: > > > > >> Tested with MSSQL 2008 and DB2 > > > > >> If you connect existing table with primarykey and use writable=False > > > >> to any of the field on the form, it will show the following error. > > > > >> Traceback (most recent call last): > > > >> File "C:\web2py\gluon\restricted.py", line 194, in restricted > > > >> exec ccode in environment > > > >> File "C:/web2py/applications/otwitter/controllers/default.py", line > > > >> 91, in <module> > > > >> File "C:\web2py\gluon\globals.py", line 149, in <lambda> > > > >> self._caller = lambda f: f() > > > >> File "C:/web2py/applications/otwitter/controllers/default.py", line > > > >> 33, in test > > > >> if form.process().accepted: > > > >> File "C:\web2py\gluon\html.py", line 1950, in process > > > >> self.validate(**kwargs) > > > >> File "C:\web2py\gluon\html.py", line 1898, in validate > > > >> if self.accepts(**kwargs): > > > >> File "C:\web2py\gluon\sqlhtml.py", line 1238, in accepts > > > >> fields[field.name] = self.record[field.name] > > > >> TypeError: 'NoneType' object is not subscriptable > > > > >> This is really critical for my project because I cannot use > > > >> writable=False to the fields I want to protect. > > > > >> Table definition > > > >> -------------------------------- > > > >> db.define_table('test', > > > >> Field('mykey'), > > > >> Field('field1'), > > > >> Field('field2'), > > > >> primarykey=['mykey'], > > > >> migrate=False) > > > > >> controller > > > >> --------------------------------- > > > >> def test(): > > > >> db.test.field2.writable=False > > > >> form = SQLFORM(db.test) > > > >> if form.process().accepted: > > > >> response.flash = 'form accepted' > > > >> elif form.errors: > > > >> response.flash = 'form has errors' > > > >> return dict(form=form) > > > > >> view > > > >> ---------------------------------- > > > >> {{extend 'layout.html'}} > > > >> <h1>test</h1> > > > >> {{=form}}

