﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
22878	DateTimeField auto_now_add, auto_now  & CreateView	FoxMaSk	nobody	"Hi,
I think I spotted a bug with auto_now_add and auto_now in the models.

Here are the details to reproduce it

'''in a models.py'''
 
{{{#!python
class Foobar(models.Model):
    created = models.DateTimeField(auto_now_add=True)
}}}
 
'''in a views.py'''

{{{#!python
class FoobarCreateView(CreateView):
    model = Foobar
    fields = [ 'created' ]
}}}

will produce the error :
{{{
Unknown field(s) created specified for Foobar
}}}
 
To try to trakc the error, I put a ""print fields"" line 285 of the file django/forms/models.py in the class ModelFormMetaclass just before

{{{#!python
            # make sure opts.fields doesn't specify an invalid field
            none_model_fields = [k for k, v in six.iteritems(fields) if not v]
}}}

which gives :
{{{
{u'created': None}
}}}
if I drop the auto_now_add from the model I get :
{{{
u'created': <django.forms.fields.DateTimeField object at 0x23bca10>
}}}
and get no error


The exact same behavior occurs with '''auto_now'''

Regards"	Bug	closed	Uncategorized	1.6	Normal	invalid			Unreviewed	0	0	0	0	0	0
