Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

model_to_dict is not returning DateTimeField with auto_now_add = True

I have created a model as:

class Job(models.Model):
    jobId = models.AutoField(primary_key = True)
    startTime = models.DateTimeField(auto_now_add = True)

When I'm doing

print(model_to_dict(job)) 

I'm getting only

{'jobId': 1}

as output. Why 'startTime' filed is not coming in the output? Please help me with this issue.

like image 561
pkgajulapalli Avatar asked Dec 22 '25 00:12

pkgajulapalli


1 Answers

A: model_to_dict is only outputting editable fields.

B: startTime is not set editable because of the auto_now_add.

So I guess you end up with one of the methods from this question.

like image 192
RickyA Avatar answered Dec 24 '25 16:12

RickyA



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!