Error dateTimeField input format

Why django gives me an error:

TypeError: __init__() got an unexpected keyword argument 'input_formats' at start_time=models.DateTimeField(input_formats='%d-%m-%y %H:%M') 

Is there something wrong with the input format? What should I do if I want the format to be date - month - year hour minute ?

+4
source share
3 answers

You are confusing the DateTimeFields model and the DateTimeFields form . Models do not accept input_formats arguments, forms do.

From Working with forms : a library of forms and APIs (which seems like what you like) - this helps you create HTML forms, perform input validation, etc.

From Models and Databases : A model is a single, final source of data about your data. It contains the main fields and behavior of the data you store. As a rule, each model is mapped to one database table.

+3
source

models.DateTimeField does not accept any arguments passed to it under the name input_formats .

What you are looking for is form.DateTimeField , for example:

 form.DateTimeField(input_formats=['%d-%m-%y %H:%M',]) 

Formats should be in list .

0
source
  • input_formats is a property of form.DateTimeField() , not models.DateTimeField()

  • According to the Doc, input_formats should be a list or tuple.

0
source

All Articles