Ranjith Ranjith - 7 months ago 77
Python Question

How can i set a default datetime value in eve?

For example, for a key

'joinDate' : {'type' : 'datetime'}

How could i make it automatically get posted with the current date without being explicitly give in POST method.

gcw gcw

You can set the default value for a datetime field on the schema definition, like so:

from datetime import datetime

your_schema = {
    'joinDate': {
        'type': 'datetime',
        'default': datetime.utcnow()
    # rest of schema

In the example, current UTC time is set to joinDate if it is not present in the POST. Check schema definition rules here.