Once again, thank you. I'll get there in the end.

On Sunday, 4 January 2015 02:37:09 UTC, Massimo Di Pierro wrote:
>
> I would do:
>
> db.define_table(
>     'shoe',
>     Field('model',db.model),
>     Field('purchased','date'),
>     Field('price','integer'),
>     auth.signature, # include created_by and created_on
>     format=lambda r: '%s %s %s' % (r.model.manufacturer.name
> ,r.model.model,r.purchased)) 
>
> along with a common filter as you suggested:
>
> db.shoe._common_filter = lambda query: db.shoe.created_by == auth.user_id 
>
> Massimo
>
>
>
> On Saturday, 3 January 2015 13:00:24 UTC-6, Gary Cowell wrote:
>>
>> Hello
>>
>> Sorry for the probably obvious questions, but I do search for answers 
>> honest :)
>>
>> Anyway, what I want is for my table rows to be user specific. Such that 
>> when each user registers, the database looks empty to them, until they 
>> start creating rows in their forms. 
>>
>> I have added these definitions to each table:
>>
>> db.define_table(
>>     'shoe',
>>     Field('model',db.model),
>>     Field('purchased','date'),
>>     Field('price','integer'),
>>     Field('created_on', 'datetime',
>>           default=request.now, update=request.now, writable=False),
>> *    Field('created_by', 'reference auth_user',*
>> *          default=auth.user_id, update=auth.user_id, writable=False),*
>>     format=lambda r: '%s %s %s' % (r.model.manufacturer.name
>> ,r.model.model,r.purchased)) 
>>
>> So I've added created_by referencing auth_user, and this places the 
>> logged in user into the row
>>
>> I could add code to the controller, the simple controller looks like
>>
>> @auth.requires_login()
>> def shoe():
>>    form = SQLFORM(db.shoe)
>>    if form.process().accepted:
>>        response.flash = 'form accepted'
>>    elif form.errors:
>>        response.flash = 'form has errors'
>>    else:
>>        response.flash = 'please fill out the form'
>>    return dict(form=form)
>>
>> Perhaps with a SQLFORM.factory somehow?
>>
>> Or is CRUD the way to go? I have no idea about CRUD yet (nor much of an 
>> idea about most of this right now, but I'm learning)
>>
>> Or perhaps using common_filter? Somehow like this:
>>
>> table._common_filter = lambda query: db.shoe.created_by == auth.user.id 
>>
>> I don't mind really which way this gets done, but if there's a canonical 
>> way, or a best practice way, I'd like to learn that, instead of the 'wrong 
>> but works' way.
>>
>> Thanks!
>>
>> Gary
>>
>>

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to