>From the docs for auto_now_add:

Automatically set the field to now when the object is first created. Useful 
for creation of timestamps. Note that the current date is *always* used; 
it’s not just a default value that you can override. So even if you set a 
value for this field when creating the object, it will be ignored. If you 
want to be able to modify this field, set the following instead of 
auto_now_add=True:

   - For DateField 
   
<https://docs.djangoproject.com/en/1.11/ref/models/fields/#django.db.models.DateField>:
 
   default=date.today - from datetime.date.today() 
   <https://docs.python.org/3/library/datetime.html#datetime.date.today>
   - For DateTimeField 
   
<https://docs.djangoproject.com/en/1.11/ref/models/fields/#django.db.models.DateTimeField>:
 
   default=timezone.now - from django.utils.timezone.now() 
   <https://docs.djangoproject.com/en/1.11/ref/utils/#django.utils.timezone.now>


https://docs.djangoproject.com/en/1.11/ref/models/fields/#django.db.models.DateField.auto_now_add

The change to raise FieldError for non-editable fields was meant to prevent 
bugs, not to block devs from doing what they want. See 
https://code.djangoproject.com/ticket/26238, and please try to be less 
antagonistic.

On Monday, May 8, 2017 at 6:30:36 AM UTC-4, [email protected] wrote:
>
> Hi.
>
> After upgrading to 1.11 I'm getting this error:
>
> FieldError: created_at cannot be specified for <MyModel> model form as it 
> is a non-editable field.
>
> First of all, the model contains created_at field declared as 
> DateTimeField(auto_now_add=True). Probably that's why it is non-editable. 
> But I cannot set editable=True - the change has no effect.
> My application allows overriding "created_at" value, because there are 
> more than one separate input channels, and I have such cases. Other relies 
> on auto_now_add. 
>
> I want to leave auto_now_add=True as is, and have possibility to override 
> it. 
> How to achieve that? 
>
> PS. Somebody asked me why I'm considering leaving Django, and this is a 
> real example of worst changes in Django in last years. Breaking 
> compatibility and blocking a dev to do what he want. There is nothing wrong 
> with overriding such value.
>
> Marcin
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" 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].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/41e69d11-e0ab-4b1b-a78d-cf4db968df0e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to