Rin
Rin

Reputation: 17

errors when trying to use model with DateField that contains null

I have a model with DateField that contains null = True, blank = True and when I use it somewhere, I got errors below:

begin_date= models.DateField(verbose_name=_("Begin date"),null=True, blank=True)
errors: [{loc: ["begin_date"], msg: "none is not an allowed value", type: "type_error.none.not_allowed"}]
0: {loc: ["begin_date"], msg: "none is not an allowed value", type: "type_error.none.not_allowed"}

I use ValidationError from Pydantic, it also triggers because of that

I know that there's a way like set allow_none to True but I have no clue how to write it correctly. I'm completely new to programming and English is not my native so sorry for mistakes.

Upvotes: 1

Views: 201

Answers (1)

waqaramjad606
waqaramjad606

Reputation: 26

just remove null=true, blank=true and add begin_date=models.DateField(auto_now_add=True) This will automatically add date when you insert that in db. For more check django dateField documentation

Upvotes: 1

Related Questions