try give a default to the blob field.

On Jun 4, 3:38 am, cjparsons <[email protected]> wrote:
> I want to store images in the database and I'm having trouble with
> my SQLFORM. I've copied the example from the manual but find that
> the image doesn't go into the database on 'new'. I'm on web2py
> Version 1.63.3
>
> Apologies in advance if it's a typo.
>
> 1) With no argument (="insert" form) I get an exception in one of the
> functions called from
> form.accepts
>
> IntegrityError: (1062, "Duplicate entry '0' for key 1")
>
> 2) With an argument (="update" form) it seems to work OK though I
> only tried changing the title
>
> 3) With the delete box ticked at the bottom of the form the record
> doesn't seem to be deleted
>
> 4) I think the new version of web2py automatically stores the
> filename, but I'm not sure this will work with my model
>
> In the model:
>
> db.define_table("images",
>       SQLField("title",comment="optional"),
>       SQLField("notes", "text", comment="optional"),
>       SQLField("image_blob", "blob", readable=False, writable=False),
>       SQLField("image", "upload", uploadfield="image_blob"),
>       SQLField("thumbnail_data", "blob", default=None,
> writable=False,readable=False),
>       SQLField("filename", length=128 ),
>       timestamp
>       )
>
> controller:
>
> def image_edit():
>    form = None
>    formFields = ['title','notes','image']
>
>    if len(request.args):
>       records = db(db.images.id==request.args[0]).select()
>    if len(request.args) and len(records):
>       url=URL(r=request,f='download')
>       form=SQLFORM(db.images,records
> [0],deletable=True,upload=url,fields=formFields)
>    else:
>       form=SQLFORM(db.images,fields=formFields)
>
>    if form.accepts(request.vars,session):
>       response.flash="Image accepted, id = " + str(request.vars.id)
>    elif form.errors:
>       response.flash='image upload failed' + str(form.errors)
>    return dict(form=form)
>
> Thanks, Chris
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to