Opened 7 years ago

Closed 4 years ago

Last modified 4 years ago

#6434 closed (fixed)

auto_now and auto_now_add documentation

Reported by: jokull@… Owned by: adamnelson
Component: Documentation Version: master
Severity: Keywords: datefield auto_now auto_now_add
Cc: mk@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

http://www.djangoproject.com/documentation/model-api/#datefield[[BR]]
The datetime.datetime.now and datetime.date.today callables or a field subclass should probably be suggested to meet these needs.

Attachments (2)

6434-dyn.patch (6.7 KB) - added by mk 7 years ago.
auto-add-note.diff (580 bytes) - added by adamv 4 years ago.
Alternate docs-only patch.

Download all attachments as: .zip

Change History (12)

comment:1 Changed 7 years ago by Alex

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Adding a default doesn't exactly do the same thing, you would also need to override the save method of the model(especially for auto_now), I also agree they should be deprecated, however we need to document the alternative.

comment:2 Changed 7 years ago by jacob

  • Triage Stage changed from Unreviewed to Accepted

Changed 7 years ago by mk

comment:3 Changed 7 years ago by mk

  • Cc mk@… added
  • Has patch set
  • Keywords auto_now auto_now_add added
  • Patch needs improvement set

Some documentation is included but it's _very_ lacking. As per the discussion in a mailing list thread[1] I added Auto[Add]{Date,DateTime,Time}Field classes to django/db/models/fields/init.py

I think this functionality is used often and therefore might deserve a place in Django proper.

[1]: http://groups.google.com/group/django-developers/browse_thread/thread/4cd631c225cb4e52

comment:4 Changed 5 years ago by CollinAnderson

  • Summary changed from auto_now and auto_now_add should me marked for soon-to-be-deprecated to auto_now and auto_now_add documentation

I believe that the current attitude towards auto_now and auto_now_add is that they become editable=False automatically. This needs to be documented, and should probably explain the common pitfalls and recommend an alternative method.

Current documentation: http://docs.djangoproject.com/en/dev/ref/models/fields/#datefield

comment:5 Changed 5 years ago by adamnelson

  • Owner changed from nobody to adamnelson

Nobody seems to be working on this so I'll take it.

comment:7 Changed 5 years ago by bjunix

I just stumbled upon this documentation 'bug'. tried to explicity include a DateField with auto_now_add=True in a ModelForm. After rethinking the problem it is clear that the auto_now_add field is not editable and thus excluded from the form automatically. But I think it would have helped if this behavior was documented somewhere.

Changed 4 years ago by adamv

Alternate docs-only patch.

comment:8 Changed 4 years ago by timo

  • Patch needs improvement unset

comment:9 Changed 4 years ago by timo

  • Resolution set to fixed
  • Status changed from new to closed

(In [14923]) Fixed #6434 - Add clarifying note about auto_now and auto_now_add. thank adamv for the patch.

comment:10 Changed 4 years ago by timo

(In [14924]) [1.2.X] Fixed #6434 - Add clarifying note about auto_now and auto_now_add. thank adamv for the patch.

Backport of r14923 from trunk.

Note: See TracTickets for help on using tickets.
Back to Top