Ranjith Ranjith - 1 year ago 135
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
Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download