new field in define_tables()

26 views
Skip to first unread message

Brendan Hayward

unread,
Feb 15, 2015, 9:38:57 PM2/15/15
to web2py-d...@googlegroups.com
I wanted to submit a patch, but I thought I'd ask first.

I looked around for previous discussion, this was the closest to what I've done: https://groups.google.com/d/topic/web2py/M8vXPX6rExU/discussion.

It would be nice to have the date created field by default, it's one of the first things I look at when dealing with users, customers etc on any platform, not just web2py sites.

Currently I've done this in my model:

    auth.settings.extra_fields['auth_user'] = [Field( 'time_stamp', type='datetime', default=request.now )]

What I think I would like is to have this in Auth.define_tables:

    Field('date_created', type='datetime', default=datetime.datetime.utcnow()), #I've used datetime because request is not defined in gluon.tools.py file, gives a NameError when I run web2py on linux with apache


Anthony

unread,
Feb 16, 2015, 7:14:00 AM2/16/15
to web2py-d...@googlegroups.com
I don't think I would make that a default field, as not everyone will need it (registration events are already stored in auth_event).

Note, in tools.py, you can refer to current.request.

Anthony
Reply all
Reply to author
Forward
0 new messages