Opened 10 years ago

Closed 9 years ago

#89 closed defect (fixed)

DateTimeFields with auto_now_add = True in admin

Reported by: philippe.normand@… Owned by: adrian
Component: contrib.admin Version: 1.1
Severity: minor Keywords: date
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Expose a DateTimeField with auto_now_add = True to the admin, try to add a new object. You can see the date field with empty values (no calendar, etc). Save the object, you'll get a validation error.

Example model:

class Article(meta.Model):
    fields = (
        meta.CharField('title', 'title', maxlength=200, core=True),
        meta.TextField('data','data'),
        meta.DateTimeField('date','date',auto_now_add=True),
    )

    admin = meta.Admin(
        fields = (
            (None, {'fields': ('title', 'date','data',)}),
        ),
    )

If i un-expose the 'date' field from admin, everything works fine.

Change History (6)

comment:1 Changed 10 years ago by adrian

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

We worked this out via IRC.

comment:2 Changed 10 years ago by jbennett@…

Would it be possible to get the resolution of this issue, or at least a helpful summary, posted here in the ticket? The IRC log site is unreachable at the moment, so there's currently no way to find out how this was solved.

comment:3 Changed 10 years ago by jbennett@…

I finally was able to pull up the IRC log; the solution, apparently, was to use 'default=meta.LazyDate()' instead of 'auto_now_add=True'. In which case, shouldn't the model documentation reflect this, at least until auto_now_add works as advertised?

comment:4 Changed 10 years ago by aCC

@jbennett

Thanks a lot for digging this up! Finally it works like it should.

comment:5 Changed 10 years ago by oliver.andrich@…

  • Resolution invalid deleted
  • Status changed from closed to reopened

I can understand the logic behind making the fields not editable when auto_now_add and auto_now are used, but then it shouldn't also be possible to use the fields inside the fields parameter inside a meta.Admin() call.

Or even better, I would highly appreciate to get them displayed read only. I don't want to change them, but I want to look at them. The admin interface is/should be a management console and not just an "item creation" workbench. At least this is what I understood.

comment:6 Changed 9 years ago by adrian

  • Resolution set to fixed
  • Status changed from reopened to closed
Note: See TracTickets for help on using tickets.
Back to Top