Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
4 Trả lời
32287 Lượt xem

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

Ảnh đại diện
Huỷ bỏ

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

Tác giả Câu trả lời hay nhất

ok thx, it works, I do this :

_defaults= {
    'record_date': fields.date.context_today,
}
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

import time

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


In this code is used to generate default current date

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

You have to add this:

import time

and you can add this to _defaults

    _defaults= {
    'date_field': lambda *a: time.strftime('%Y-%m-%d'),
}
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 1 20
604
1
thg 11 22
3204
3
thg 11 21
25837
1
thg 8 15
5359
2
thg 3 15
5277