Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why isn't keyword DateField.input_formats recognized in django 1.0.2 and Python 2.5?

Tags:

python

django

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'])
like image 760
Mitch Avatar asked Mar 27 '09 15:03

Mitch


People also ask

What is DateField in Django?

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.

How does Django save current date and time in database?

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.


1 Answers

Having looked at the docs, like you suspected, models.DateField doesn't have an input_formats, but forms.DateField does (as does forms.DateTimeField)

like image 160
Powerlord Avatar answered Nov 14 '22 21:11

Powerlord