#22878: DateTimeField auto_now_add, auto_now & CreateView
-------------------------------+--------------------
Reporter: foxmask | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 1.6
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
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
--
Ticket URL: <https://code.djangoproject.com/ticket/22878>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/050.fe838b654b83e0c44752d5395358a3a9%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.