跳至內容
選單
此問題已被標幟
4 回覆
32256 瀏覽次數

Hi. I create a field date in my module class file, and I want to put automatically the day of today (for example) as default date. Help me please. thx

頭像
捨棄

from_date = fields.Date(string="From Date" ,default=datetime.now())

作者 最佳答案

ok thx, it works, I do this :

_defaults= {
    'record_date': fields.date.context_today,
}
頭像
捨棄
最佳答案

import time

admission_date = fields.Date('Admission Date', default=date.today())


In this code is used to generate default current date

頭像
捨棄
最佳答案

You have to add this:

import time

and you can add this to _defaults

    _defaults= {
    'date_field': lambda *a: time.strftime('%Y-%m-%d'),
}
頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
0
1月 20
604
1
11月 22
3194
3
11月 21
25813
1
8月 15
5347
2
3月 15
5277