Opened 7 years ago

Closed 7 years ago

#8899 closed (fixed)

Admin "exclude" option should accept both lists and tuples

Reported by: anonymous Owned by: nobody
Component: contrib.admin Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Hi,
On http://docs.djangoproject.com/en/dev/ref/contrib/admin/#ref-contrib-admin
at the exclude example it says:

class AuthorAdmin(admin.ModelAdmin):
    fields = ('name', 'title')

class AuthorAdmin(admin.ModelAdmin):
    exclude = ('birth_date',)

But it should be

class AuthorAdmin(admin.ModelAdmin):
    fields = ['name', 'title']

class AuthorAdmin(admin.ModelAdmin):
    exclude = ['birth_date',]

Attachments (1)

8899.exclude-tuple.diff (1.8 KB) - added by julien 7 years ago.
patch + tests

Download all attachments as: .zip

Change History (8)

comment:1 Changed 7 years ago by dc

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

You can use any python sequence type. So tuples are OK.

comment:2 Changed 7 years ago by chrisdpratt

  • Resolution invalid deleted
  • Status changed from closed to reopened

Actually, I followed the docs and used a tuple and received the following error:

Traceback:
File "/Library/Python/2.5/site-packages/django/core/handlers/base.py" in get_response

  1. response = callback(request, *callback_args, callback_kwargs)

File "/Library/Python/2.5/site-packages/django/contrib/admin/sites.py" in root

  1. return self.model_page(request, *url.split('/', 2))

File "/Library/Python/2.5/site-packages/django/views/decorators/cache.py" in _wrapped_view_func

  1. response = view_func(request, *args, kwargs)

File "/Library/Python/2.5/site-packages/django/contrib/admin/sites.py" in model_page

  1. return admin_obj(request, rest_of_url)

File "/Library/Python/2.5/site-packages/django/contrib/admin/options.py" in call

  1. return self.add_view(request)

File "/Library/Python/2.5/site-packages/django/db/transaction.py" in _commit_on_success

  1. res = func(*args, kw)

File "/Library/Python/2.5/site-packages/django/contrib/admin/options.py" in add_view

  1. ModelForm = self.get_form(request)

File "/Library/Python/2.5/site-packages/django/contrib/admin/options.py" in get_form

  1. "exclude": exclude + kwargs.get("exclude", []),

Exception Type: TypeError at /lifestyle/admin/lifestyle/post/add/
Exception Value: can only concatenate tuple (not "list") to tuple

As a list, no errors are generated. If it's supposed to allow both types, then that functionality is broken, so one of Django or the docs needs to be fixed.

comment:3 Changed 7 years ago by brosner

  • Triage Stage changed from Unreviewed to Accepted

The code is wrong in this case. It should be fixed.

comment:4 Changed 7 years ago by mtredinnick

  • Component changed from Documentation to django.contrib.admin
  • Summary changed from Type: () should be [] to Admin "fields" and "excludes" should accept both lists and tuples

Changed the title to something less cryptic.

Changed 7 years ago by julien

patch + tests

comment:5 Changed 7 years ago by julien

  • Summary changed from Admin "fields" and "excludes" should accept both lists and tuples to Admin "exclude" option should accept both lists and tuples

Added patch, and also changed summary as only "exclude" is problematic ("fields" already accepts both types).

comment:6 Changed 7 years ago by danielr

  • Has patch set

comment:7 Changed 7 years ago by mtredinnick

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

This was fixed in passing in [9086].

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