Hi,
I got two tables which reference each other. to do that I added a third 
called reference_image
db.define_table('Images',
    Field('Title',length=1024),
    Field('Image','upload'),
    Field('thumb','upload',writable=False,readable=False),
    Field('Source',db.Source, requires=IS_IN_DB(db,'Source.id','Source.Name'
)),
    format = '%(Title)s'
    )

db.define_table('Media',
    Field('Title',length=512),
    Field('Content','text'),
    Field('Views','integer',default=0),
    Field('TitelImage169','reference Images', requires=IS_EMPTY_OR(IS_IN_DB(
db, db.Images.id,'Images.Bildunterschrift'), null=None)),
    format = '%(Title)s'
    )



db.define_table("image_references",
    Field("image_id", "reference Images",writable=False,readable=False),
    Field("Media", "reference Media")
    )    

when I enter an image I need to specify which media it belongs to. So I did 
that with an SQLForm.factory(db.Image,db.image_reference)
my problem is I got no Idea how I fill the image_references.image_id. Since 
the image Id has not been created at the time of the commit.

my controller for the insert image is already pretty big because its 
creating the thumbnails for the image. But here it is:

def newImage():
    dbtable = db.Images          #uploads table name
    if len(request.args):
        records = db(dbtable.id==request.args[0]).select()
    if len(request.args) and len(records):
        form = SQLFORM(dbtable, records[0], deletable=True)
    else:
        form = SQLFORM.factory(dbtable,db.image_references)
    if form.accepts(request.vars, session):
        response.flash = 'Entry for Images Database accepted,start creating 
thumb'
        makeThumbnail(dbtable,form.vars.id,(200,200))
        thisImage=db(dbtable.id==form.vars.id).select()[0]
    elif form.errors:
        response.flash = 'Error in Form for Images Database'
    list = crud.select(dbtable)
    return dict(form=form,list=list)


thanks

-- 

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


Reply via email to