This comes up once in a while. I will try to make it easy. Anyway:

The problem is if you need a default image, perhaps you do not want to copy 
it for every record the needs it.
The proper way would be to upload it once and the set the default to the 
value of the upload field for that record.

db.define_table('mytable', Field('Cover', 'upload', default='xxx'), ...)

where xxx you would get from running

web2py.py -S yourapp -M -N
>>> import os
>>> print db.mytbale.Cover.store(open(os.path.join(request.folder, 'static',
 'images','no-user-image.gif'),'rb'))

Massimo



On Wednesday, 11 April 2012 11:23:49 UTC-5, Anthony wrote:
>
>
>
> On Wednesday, April 11, 2012 5:15:51 AM UTC-4, Hassan Alnatour wrote:
>>
>> Dear ALL,
>>
>> how can i make a default image for a image upload field in db i tried 
>> this but its not working :
>>
>>
>> Field('Cover','upload',default="URL('static','images')/no-user-image.gif"),
>>
>
> I haven't tried it, but maybe:
>
> import os
> db.define_table(...,
>     Field('Cover', 'upload',
>           default = lambda: open(os.path.join(request.folder, 'static', 
> 'images',
>                                  'no-user-image.gif'), 'rb')),
>     ...)
>
> Anthony
>

Reply via email to