How to Convert Python datetime to firestore timestamp format

'Cannot convert to a Firestore Value',, 1, 16)

raise TypeError(

TypeError: ('Cannot convert to a Firestore Value',, 1, 16), 'Invalid type', <class ''>)

Related documentation

 def to_json(self):

137             import pdb;pdb.set_trace()

138             json = {

139  ->             "id" :,

140                 "vehicle_merk" :,

141                 "vehicle_model":,

142                 "price": str(self.price),

143                 "created": self.created , #strftime("%Y-%m-%dT%H:%M:%SZ"), # strftime("%Y_%m_%d_%H_%M_%S_%f")

144                 "fuel_type": self.fuel_type,

(Pdb) type(self.created)

<class 'datetime.datetime'>

(Pdb) type(self.first_registration)

<class ''>

The issue was with using a `DateField` in Django instead of a `DateTimeField`. The `DateField` type does not get automatically converted to Firestore's timestamp format, requiring a change in the field type.

For example, if you have a Django model with a `DateField` that you want to store in Firestore, you can convert it to a `DateTimeField` by adding a default time value, and then convert it to a Firestore timestamp. Here's an example: