3

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.

pkgajulapalli
  • 1,066
  • 3
  • 20
  • 44

1 Answers1

4

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.

Community
  • 1
  • 1
RickyA
  • 15,465
  • 5
  • 71
  • 95