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
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)



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.

Reply via email to