try this:

@auth.requires_login()
def addpump():
    """ add pump """
    form = SQLFORM(db.pumpData)
    if form.process().accepted:
            redirect(URL('listpumps')) 
   return dict(form=form)

@auth.requires_login()
def listpumps():
      query = db(db.carOwner.carowner==auth_user.id).select()
    return dict(query=query)

in the view lispumps.html

{{extend "layout.html"}}

{{fro each in query:}}
      name {{=ath_user.first_name}}

            cars   {{=UL(LI(eath.car.name))}}
{{pass}}






El viernes, 20 de diciembre de 2013 06:58:00 UTC-5, [email protected] 
escribió:
>
> Hi!
>
> I'm new in web2py and I started to make a simple application to test it.
>
> My db.py file is like this:
>
> # -*- coding: utf-8 -*-
> from gluon.tools import *
>
> db = 
> DAL('mysql://root:****@localhost/web2pyPumpIt',pool_size=5,check_reserved=['all'])
>
> auth = Auth(db)
> auth.define_tables()
>
> ########################################################################
> ## Define your tables below (or better in another model file) for example
> ##
> ## >>> db.define_table('mytable',Field('myfield','string'))
> ##
> ## Fields can be 'string','text','password','integer','double','boolean'
> ##       'date','time','datetime','blob','upload', 'reference TABLENAME'
> ## There is an implicit 'id integer autoincrement' field
> ## Consult manual for more options, validators, etc.
> ##
> ## More API examples for controllers:
> ##
> ## >>> db.mytable.insert(myfield='value')
> ## >>> rows=db(db.mytable.myfield=='value').select(db.mytable.ALL)
> ## >>> for row in rows: print row.id, row.myfield
> #########################################################################
>
> db.define_table('brand',
>           Field('name', 'string'),
>           Field('country', 'string'),
>           format='%(name)s')
>
> db.define_table('car',
>           Field('name', 'string'),
>           Field('brand_id', 'reference brand'),
>           Field('modelyear', 'integer'),
>           format='%(name)s')
>
> db.define_table('carOwner',
>           Field('carowner', 'reference auth_user'),
>           Field('car', 'reference car'))
>
> db.define_table('pumpData',
>           Field('pumpdate', 'date'),
>           Field('km', 'double'),
>           Field('liters', 'double'),
>           Field('price', 'double'),
>           Field('car', 'reference car'),
>           Field('created_on', 'datetime', default=request.now),
>           Field('created_by', 'reference auth_user', default=auth.user_id))
>
> db.car.id.readable = db.car.id.writable = False
> db.car.name.requires = IS_NOT_IN_DB(db, 'car.name')
> db.car.name.requires = IS_NOT_EMPTY()
> db.car.brand_id.requires = IS_NOT_EMPTY()
> db.car.brand_id.requires = IS_IN_DB(db, 'brand.id', '%(name)s')
>
> db.brand.name.requires = IS_NOT_IN_DB(db, 'car.name')
> db.brand.name.requires = IS_NOT_EMPTY()
> db.brand.country.requires = IS_NOT_EMPTY()
>
> db.pumpData.pumpdate.requires = IS_NOT_EMPTY()
> db.pumpData.km.requires = IS_NOT_EMPTY()
> db.pumpData.liters.requires = IS_NOT_EMPTY()
> db.pumpData.price.requires = IS_NOT_EMPTY()
> db.pumpData.car.requires = IS_NOT_EMPTY()
> db.pumpData.car.requires = IS_IN_DB(db, 'car.id', '%(name)s')
>
> db.pumpData.created_by.readable = db.pumpData.created_by.writable = False
> db.pumpData.created_on.readable = db.pumpData.created_on.writable = False
>
> owners_and_cars = db((db.car.id==db.carOwner.car) & (db.auth_user.id == 
> db.carOwner.carowner))
> ## after defining tables, uncomment below to enable auditing
> # auth.enable_record_versioning(db)
>
> I create a user, a brand, a car and then I assigned the car to the user. 
>
> My problem is that when I try to create a SQLFORM of pumpdata in 
> controller like this:
> @auth.requires_login()
> def addpump():
>     """ add pump """
>     form = SQLFORM(db.pumpData);
>     form.process(next=URL('listpumps'))
>     return dict(form=form)
>
> I get all the cars! Now I only want the cars that the logged user own, not 
> all. How can I do that? My other problem is that I put on the fields 
> required but all the selects has a empty option.
>
> Regards!!
>
>
>

-- 
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to