How to use crud.select(db, query) to extract values in db table

54 views
Skip to first unread message

Gideon George

unread,
Dec 3, 2014, 11:25:31 PM12/3/14
to web...@googlegroups.com
This is my db
db = DAL('sqlite://storage.sqlite')
db.define_table('entry',
                Field('name'),
                Field('location'),
                Field('state_of_origin'),
                Field('local_govt'),
                Field('file', 'upload'),
                Field('posted_on','datetime',readable=False,writable=False)
                )


I want to extract only the values from my db table called "entry" using crud. I understand i have to do this
 name = crud.select(db.entry, query)

But because i don't know the fomular for extracting the query, I did this
    name = crud.select(db.entry, fields=['name'])
I got the fields with the values as result.

I just want the values only! Please help me with the formular for getting each of the values in my table using query.

Action Controller

def zone():
    db.entry.posted_on.default = request.now
    form=crud.create(db.entry,  next=URL('zone'), message=T('Record created'))
    name = crud.select(db.entry, fields=['name'])
    location  = crud.select(db.entry, fields=['location'])
    state = crud.select(db.entry, fields=['state_of_origin'])
    lga = crud.select(db.entry, fields=['local_govt'])
    image = crud.select(db.entry, fields=['file'])

View

 I rep {{=lga}}, {{=state}} State. By {{=name}}<br/>
            lives in {{=location}} on {{=how can I show the time here?}}
        
ABOVE IS EXACTLY HOW I WANT IT TO APPEAR.

Dave S

unread,
Dec 5, 2014, 2:52:27 PM12/5/14
to web...@googlegroups.com


On Wednesday, December 3, 2014 8:25:31 PM UTC-8, Gideon George wrote:
[model, controller skipped]

View

 I rep {{=lga}}, {{=state}} State. By {{=name}}<br/>
            lives in {{=location}} on {{=how can I show the time here?}}

What time do you want to show?  The only time in your model is the posted field.  If you're using that, the default is for the DAL to return that as a string in ISO 8601 format.  If you want to use the current time (which will change each time the page is accessed), then you can either use datetime.datetime.now() in your controller (and thus use server time)  (you use the value to add an extra item to the dictionary your controller returns), or use javascript to access the time on the user's computer.

If the time is coming from another source, then you would need to understand what form that value is in, and how to convert it to the correct string format.

/dps

Anthony

unread,
Dec 5, 2014, 4:39:36 PM12/5/14
to web...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages