That's clear for me now Thank you Le jeudi 18 avril 2013 14:32:12 UTC+2, Anthony a écrit : > > This syntax: > > 'reference %s' % auth.settings.table_user_name > > is not about being lazy tables compliant -- it is just a way to construct > a string when part of the string is stored in a variable (another option > would be 'reference ' + auth.settings.table_user_name). You could just as > easily do: > > 'reference auth_user' > > The former syntax just allows for cases where you don't want to hard-code > the name of the user table into your field definition (in case you decide > to change it at some point). The problem with your original field > definition was that you specified the field object itself (i.e., > auth.settings.table_user), which requires that the table already exists. > The "reference" syntax just requires the table name, not the table object. > > Anthony > > On Thursday, April 18, 2013 8:25:50 AM UTC-4, Loïc wrote: >> >> One more question Anthony, >> If I have other tables which reference themselves like : >> >> db.define_table('mytable',Field('myfield','string')) >> db.define_table('my_other_table',Field('myTable','reference mytable')) >> >> should I replace the* 'reference mytable' *statement with* 'reference >> %s' % I_dont_know_what*' to be "lazy_tables compliant"? >> Thank you >> >> Le jeudi 18 avril 2013 13:59:18 UTC+2, Anthony a écrit : >>> >>> Have the auth tables been defined at that point. In any case, to avoid >>> pre-mature table definition, try replacing auth.settings.table_user with: >>> >>> 'reference %s' % auth.settings.table_user_name >>> >>> Anthony >>> >>> On Thursday, April 18, 2013 7:51:19 AM UTC-4, Loïc wrote: >>>> >>>> Hello All >>>> >>>> consider the example model file below : >>>> >>>> db = DAL('sqlite://storage.sqlite') >>>> >>>> signature = db.Table(db,'auth_signature', >>>> Field('created_on','datetime',default=request.now, >>>> writable=False,readable=False, label=T('Created on')), >>>> Field('created_by',auth.settings.table_user,default=auth. >>>> user_id, >>>> writable=False,readable=False, label=T('Created by')), >>>> Field('modified_on','datetime',update=request.now,default= >>>> request.now, >>>> writable=False,readable=False, label=T('Modified on')), >>>> Field('modified_by',auth.settings.table_user, >>>> default=auth.user_id,update=auth.user_id, >>>> writable=False,readable=False, label=T('Modified by')) >>>> ) >>>> >>>> db._common_fields.append(signature) >>>> >>>> db.define_table('mytable',Field('myfield','string')) >>>> db.mytable.myfield.requires = IS_EMPTY_OR(IS_URL()) >>>> >>>> Then, if I want to activate lazy_tables >>>> db = DAL('sqlite://storage.sqlite', lazy_tables=True) >>>> >>>> I got the following error that I don't really understand. >>>> Can anyone explain me? >>>> Thank you >>>> >>>> Error ticket for "test" Ticket ID >>>> >>>> 127.0.0.1.2013-04-18.13-47-51.4d08ccf5-8d25-4cf1-a8dd-081d76046b7a >>>> <type 'exceptions.AttributeError'> 'NoneType' object has no attribute >>>> 'startswith' Version web2py™ Version >>>> 2.4.5-stable+timestamp.2013.03.18.22.46.22 Python Python 2.7.3: >>>> C:\Python27\python.exe (prefix: C:\Python27) Traceback >>>> >>>> 1. >>>> 2. >>>> 3. >>>> 4. >>>> 5. >>>> 6. >>>> 7. >>>> 8. >>>> 9. >>>> 10. >>>> 11. >>>> 12. >>>> 13. >>>> >>>> Traceback (most recent call last): >>>> File "C:\Users\MCR\Google Drive\loic\web2py\web2py\gluon\restricted.py", >>>> line 212, in restricted >>>> exec ccode in environment >>>> File "C:/Users/MCR/Google >>>> Drive/loic/web2py/web2py/applications/test/models/db.py" >>>> <http://127.0.0.1:8000/admin/default/edit/test/models/db.py>, line 101, in >>>> <module> >>>> db.mytable.myfield.requires = IS_EMPTY_OR(IS_URL()) >>>> File "C:\Users\MCR\Google Drive\loic\web2py\web2py\gluon\dal.py", line >>>> 7790, in __getattr__ >>>> return self.lazy_define_table(tablename,*fields,**args) >>>> File "C:\Users\MCR\Google Drive\loic\web2py\web2py\gluon\dal.py", line >>>> 7714, in lazy_define_table >>>> polymodel=polymodel) >>>> File "C:\Users\MCR\Google Drive\loic\web2py\web2py\gluon\dal.py", line >>>> 776, in create_table >>>> elif field_type.startswith('reference'): >>>> AttributeError: 'NoneType' object has no attribute 'startswith' >>>> >>>> >>>>
-- --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.