Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
4 ตอบกลับ
32270 มุมมอง

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'),
}
อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
0
ม.ค. 20
604
1
พ.ย. 22
3197
3
พ.ย. 21
25821
1
ส.ค. 15
5348
Year only needed - how to implement? แก้ไขแล้ว
2
มี.ค. 15
5277