Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#20088 closed Bug (fixed)

Django admin log depends on User model having a field named id

Reported by: Ryan Leckey <leckey.ryan@…> Owned by: jcatalan
Component: contrib.admin Version: dev
Severity: Normal Keywords: configurable, user, model
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

See https://github.com/django/django/blob/master/django/contrib/admin/templatetags/log.py#L20

Either we need to document that a User's pk must be named id and be integral or refactor the code linked above to not depend on it.

Change History (7)

comment:1 by Ryan Leckey <leckey.ryan@…>, 11 years ago

Patch needs improvement: set

Something like the following works in my application.

def render(self, context):
    entries = LogEntry.objects.all()
    if self.user is not None:
        entries = LogEntry.objects.filter(user__exact=self.user)
    context[self.varname] = entries.select_related('content_type', 'user')[:self.limit]
    return ''

comment:2 by Aymeric Augustin, 11 years ago

Resolution: duplicate
Status: newclosed

I think that's the same problem as #20049.

comment:3 by Ryan Leckey <leckey.ryan@…>, 11 years ago

No. #20049 is about the models themselves being incapable to be acted upon if they have non-integer primary keys (I actually don't encounter that bug using mysql and InnoDB).

This issue causes Login to fail as the get_admin_log template tag is attempting to retrieve users by a relation lookup. If you change the linked code to the snippet above it works (at least in my application).

comment:4 by Aymeric Augustin, 11 years ago

Resolution: duplicate
Status: closednew

Mmm, right, this could probably be fixed independently.

comment:5 by jcatalan, 11 years ago

Owner: changed from nobody to jcatalan
Status: newassigned

comment:6 by Juan Catalano <jc@…>, 11 years ago

Resolution: fixed
Status: assignedclosed

In 054ce2aa02c88221ffa5665a4b9a5739cbbd0a39:

Fixed #20088 -- Changed get_admin_log not to depend on User id field

Before this change, the get_admin_log method would expect User model's
FK to be named id. When changing that FK name, admin/index.html
rendering would fail.

This includes:

  • Changed the use of id for the use of pk property.
  • Added a regression test that fails without the patch.

This commit refs #20088.

comment:7 by Preston Holmes <preston@…>, 11 years ago

In 7a3409fc645c3e9c839fef08f05ec3bbcd9fb9cb:

Merge pull request #931 from catalanojuan/fix-admin-log-dependency-on-user-id-field-20088

Fixed #20088 -- Changed get_admin_log not to depend on User id field

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