Re: [web2py] Re: default usage
a, i got it, thank you so much for your detail explaination and example, villas. On Sun, May 15, 2011 at 5:27 PM, villas wrote: > It is simply how that record id will be displayed when used in a > foreign key. > > e.g. > > table colors: > id: 1, name: red, > id: 2, name: yellow, > > table cars: > id: 1, descr: sport, color_id: 1 > > When you create a form for 'cars', how would you like the color_id > field to appear? > > a) a drop-down box showing id numbers 1,2 > b) a drop-down box showing red, yellow > > Most people would say b). Therefore they use record representation to > enable this to happen automatically. > > db.define_table('colors', Field('name'), format='%(name)s') > > > On May 15, 5:39 am, pbreit wrote: > > I still don't understand Record Representation. Is there a plain english > > description or, better, examples of what it actually does?
Re: [web2py] Re: default usage
i'm understand right now, thank you so much for your detail explaination. On Sun, May 15, 2011 at 5:02 AM, Anthony wrote: > On Saturday, May 14, 2011 5:37:39 PM UTC-4, 黄祥 wrote: >> >> hi, >> >> is there anyone can explain about the usage of default? >> >> e.g. on http://web2py.com/book/default/chapter/03#Adding-CRUD >> db.comment.image_id.default = image.id > > > You can read about it here: > http://web2py.com/book/default/chapter/06#Record-Representation > > It sets the default value for a field for when an insert is done without > specifying any value, and it is also used to pre-populate SQLFORM fields. > You can specify it when you define your table, but you can also change it at > other points in your code (e.g., you may specify a default where the table > is defined in your model file, but then later change the default in a > controller function). In the example above, it looks like it's being used to > pre-populate the crud form with the currently selected image. > > Anthony >