See https://stackoverflow.com/a/50045586/440323.

On Thursday, April 26, 2018 at 10:29:52 AM UTC-4, [email protected] 
wrote:
>
> Hello,
>
> I am completely new to Web2Py (please bear with me) and have the following 
> problem:
>
> I am trying to define a database and have the current year as a field 
> which should be automatically filled in using datetime. 
>
> But when I try to open the database and look at the entries I get a 
> traceback which I do not understand (see below). 
>
>
> Edit: I think it has to do something with strftime having only one 
> argument. When I am using strftime("%Y%m%d") it is working perfectly. But I 
> really only need the current year.
>
>
> Thank you
>
> **Code**
>
> import datetime
>
>            db.define_table('orders',            
>                         Field("current_year", "string",Label=T('Current 
> Year'), rdefault=datetime.datetime.now().strftime("%Y"),eadable=True, 
> writable=False))
>
>
>
> **Code using IS_DATETIME**
>
> After reading the web2py documentation I also tried this: 
>
> Field('current_year', 'string', label=T('Current Year'), 
> default=IS_DATETIME(format=T('%Y')),readable=True, writable=False))
>
>
> But I get the same traceback (see below)
>
> Thanks, any help would be appreciated
>
> **Traceback:**
>
> Traceback (most recent call last):
>   File 
> "/home/PyCatUB/web2py/applications/contacts/controllers/appadmin.py", line 
> 269, in select
>     *fields, limitby=(start, stop))
>   File "/home/PyCatUB/web2py/gluon/packages/dal/pydal/objects.py", line 
> 2020, in select
>     return adapter.select(self.query, fields, attributes)
>   File "/home/PyCatUB/web2py/gluon/packages/dal/pydal/adapters/sqlite.py", 
> line 123, in select
>     return super(SQLiteAdapter, self).select(query, fields, attributes)
>   File "/home/PyCatUB/web2py/gluon/packages/dal/pydal/adapters/base.py", 
> line 1296, in select
>     return self._select_aux(sql,fields,attributes)
>   File "/home/PyCatUB/web2py/gluon/packages/dal/pydal/adapters/base.py", 
> line 1253, in _select_aux
>     self.execute(sql)
>   File "/home/PyCatUB/web2py/gluon/packages/dal/pydal/adapters/base.py", 
> line 1388, in execute
>     return self.log_execute(*a, **b)
>   File "/home/PyCatUB/web2py/gluon/packages/dal/pydal/adapters/base.py", 
> line 1382, in log_execute
>     ret = self.get_cursor().execute(command, *a[1:], **b)
>   File "/usr/lib/python2.7/sqlite3/dbapi2.py", line 66, in 
> convert_timestamp
>     datepart, timepart = val.split(" ")
> ValueError: need more than 1 value to unpack
>

-- 
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/d/optout.

Reply via email to