So if I have this field in db.project Field('project_pdf', 'upload', label='Project PDF', comment='', uploadfolder ='app/uploads'),
I must change to Field('project_pdf', 'upload', label='Project PDF', comment='', uploadfolder ='app/uploads', default=''), what content should I put in "default" attribute? the file name? or folder path? records have same folder path but different file name. Even if I change "form.var.project_pdf", the link button won't appear? Anthony於 2016年2月29日星期一 UTC+8上午8時51分27秒寫道: > > The widget gets created when the form is initialized, so if you want to > specify a value for the file URL, you should do it by setting the "default" > attribute of the upload field in the db.project table *before* creating > the table. > > Anthony > > On Sunday, February 28, 2016 at 10:07:28 AM UTC-5, killzane wrote: >> >> I want to modify a record from db.project, and there are a reference >> field in db.project. >> So I use SQLFORM.factory to add field to put reference list name. >> >> the code I paste is simplify version >> here is full code >> project = db((db.project.id == 1) & (db.frature.project_id == >> 1)).select(db.project.ALL, db.feature.ALL).first() >> >> form = SQLFORM.factory(Field('list_name', 'string', label='List Name'), >> db.project, db.feature, table_name='project',upload=URL('download')) >> >> for t in [db.project, db.project_feature]: >> query = t.id == project.id if t == db.project else t.project_id == >> project.id >> __copydata(db(query).select(limitby=(0,1)).first(), form.vars, >> t.fields) >> >> so, that me ask another question: >> How to make SQLFORM.widgets.upload.widget work. >> I mean make the link button appear. >> what content I need to put in form.var? >> >> Anthony於 2016年2月28日星期日 UTC+8下午9時29分52秒寫道: >>> >>> Sorry, still not clear what you are trying to do, and you have not >>> explained why you are iterating over the Fields of the db.project table. >>> >>> On Sunday, February 28, 2016 at 3:48:26 AM UTC-5, killzane wrote: >>>> >>>> Because I want to add other field to the form so I use SQLFORM.factory. >>>> >>>> And this is my __copydata method >>>> def __copydata(src, dest, fields): >>>> if src: >>>> for k in fields: >>>> if src.has_key(k): >>>> dest[k] = src[k] >>>> return dict() >>>> >>>> >>>> >>>> Anthony於 2016年2月26日星期五 UTC+8下午9時08分13秒寫道: >>>>> >>>>> >>>>> for t in db.project: >>>>>> query = (t.id == request.vars.id) >>>>>> __copydata(db(query).select(limitby=(0,1)).first(), form.vars, >>>>>> t.fields) >>>>>> >>>>> >>>>> The above is confusing and cannot be the actual code, as it would >>>>> raise an exception. When you iterate over db.project, you get its Field >>>>> objects (so each value of "t" is a Field object). Field objects do not >>>>> have >>>>> ".id" or ".fields" attributes, so both of the next two lines would result >>>>> in errors. Perhaps you instead mean to be iterating over Table objects, >>>>> but >>>>> it's not clear why you would be doing that, as the form is based on just >>>>> a >>>>> single table. >>>>> >>>>> Anthony >>>>> >>>> -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- 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/d/optout.