Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
4 Odpovědi
32204 Zobrazení

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

Avatar
Zrušit

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

Autor Nejlepší odpověď

ok thx, it works, I do this :

_defaults= {
    'record_date': fields.date.context_today,
}
Avatar
Zrušit
Nejlepší odpověď

import time

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


In this code is used to generate default current date

Avatar
Zrušit
Nejlepší odpověď

You have to add this:

import time

and you can add this to _defaults

    _defaults= {
    'date_field': lambda *a: time.strftime('%Y-%m-%d'),
}
Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
0
led 20
604
1
lis 22
3173
3
lis 21
25772
1
srp 15
5325
2
bře 15
5277