With django 1.0.2 and Python 2.5, when I use the keyword DateField.input_formats
, I get the error that __init__()
got an unexpected keyword argument 'input_formats'
. When I look in the __init__
file, I don't see input_formats
as one of the acceptable keyword arguments.
I thought that input_formats
had been around long enough that it should be in there. Is the input_formats
keyword not supported in this configuration? If not, how can I acquire an updated __init__
that does support it? Thank you.
As suggested in the comment, I have added code below. I suspect the problem is that I am confusing the DateField
form and DateField
model, but I would be pleased if someone could confirm that.
from django.db import models
class Payment(models.Model):
date_paid = models.DateField(blank=True, db_index=True, input_formats=['%m/%d/%y'])
DateField is a field that stores date, represented in Python by a datetime. date instance. As the name suggests, this field is used to store an object of date created in python. The default form widget for this field is a TextInput. The admin can add a JavaScript calendar and a shortcut for “Today” explicitly.
First, open the views.py file of your Django application and import the datetime module. Next, use the datetime. now() method to get the current date and time value. Now, we can either assign this method to a variable or we can directly use this method wherever we required the datetime value.
Having looked at the docs, like you suspected, models.DateField doesn't have an input_formats, but forms.DateField does (as does forms.DateTimeField)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With