Opened 7 years ago

Closed 7 years ago

#7665 closed (duplicate)

User change list filters disappear in newforms-admin if a model has a OneToOneField to User

Reported by: AmanKow Owned by: nobody
Component: contrib.admin Version: newforms-admin
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


If I create a test project, with the bare minimum to connect to the default admin site and go to the user change list, the is_staff and is_superuser filters show up fine. If I now add a simple test app, with a single model, and that model has a OneToOneField to auth.User, then the filters do not show up in the admin change list for User.

I noticed this today after svn up to the tip r7857. I believe (but can't be positive) this was working before the holiday r7834.

# this works
class TestModel(models.Model):

# the is staff and is superuser models disappear from the admin
class TestModel(models.Model):
    user = models.OneToOneField(User)

Change History (3)

comment:1 Changed 7 years ago by AmanKow

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

I believe this must affect all model change lists in admin:

85:    def get_filters(self, request):
86:        filter_specs = []
87:        if self.list_filter and not self.opts.one_to_one_field:
88:            filter_fields = [self.lookup_opts.get_field(field_name) for field_name in self.list_filter]
89:            for f in filter_fields:
90:                spec = FilterSpec.create(f, request, self.params, self.model, self.model_admin)
91:                if spec and spec.has_output():
92:                    filter_specs.append(spec)
93:        return filter_specs, bool(filter_specs)

I think the problem is the test at line 87. In the absence of any comments, I have no idea what this is trying to prevent. I can't see any good reason to restrict a model that is one to one referenced from another model from having filters.

Also, if I add the filter query (for instance, ?is_staff__exact=1) to the url, the filtering works just fine.

comment:2 Changed 7 years ago by AmanKow

Hmmm... one final comment... this function is identical to the one in trunk at line 587

comment:3 Changed 7 years ago by zobbo

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

This is really a duplicate of #2145 I think. Model inheritance utilises one to one relationships and currently the code doesn't allow filters to work for those. Changing line 87 to just

if self.list_filter:

works for me currently.

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