T.Young
T.Young

Reputation: 55

DATETIME_FORMAT setting in Django causing delete action in Django admin to throw ValidationError

I have an issue where if I use the default value for DATETIME_FORMAT, when I select a row/rows in the django admin and select the delete action, the timestamp causes a validation error. enter image description here

enter image description here

enter image description here

If I do DATETIME_FORMAT = (( 'Y-m-d H:i:sO' )), I can remove the error. I have the feeling I am doing something seriously wrong when I have to change a default value like this. I looked through the timezone documentation but wasn't able to explain to myself why I needed to change the default in this way.

An explanation or reference to the documentation that explains this behavior would be greatly appreciated.

Update: To load the data into the database, I have a function that iterates over a dictionary to populate models, then they are written in bulk to the database. The code that does this takes the epoch and converts it to a time stamp, I give it a UTC timezone, as I know this is how I recieve the data.

    for timestamp, payload in data.items():
            
            # Map paylod keys and values to model columns
            model_data = {}

            model_data['ts'] = datetime.datetime.fromtimestamp(int(timestamp),tz=timezone.utc)
            logging.debug(f'Time Stamp: {model_data["ts"]}')

            model_data['imei'] = machine_model

            machine_data_objects.append(
                MachineData(**model_data)
                )

        MachineData.objects.bulk_create(machine_data_objects)

Upvotes: 0

Views: 27

Answers (0)

Related Questions