Skip to Content
Menu
This question has been flagged
1 Reply
6720 Views

I've got a char field and I'm trying to set the default value to the current year, but it doesn't work. Is it possible to do this? I know I could do it with compute but I need that the user can input different values if he needs to.

year = fields.Char(string='Year', default=str(datetime.now().year))

and yes I have datetime imported from datetime.

Avatar
Discard
Best Answer

def get_year(self):

    return str(datetime.now().year)

year = fields.Char(string='Year', default=get_year)

Avatar
Discard
Author

Thanks... it works, have tried that already but had the method after the field declaration. Moved it before it, and it works.

Related Posts Replies Views Activity
2
Nov 24
25099
2
May 24
5524
3
Mar 24
4967
0
Mar 24
264
3
Feb 24
11421