Opened 16 years ago

Closed 16 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: no UI/UX: no

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 Phalip 16 years ago.
patch + tests

Download all attachments as: .zip

Change History (8)

comment:1 by dc, 16 years ago

Resolution: invalid
Status: newclosed

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

comment:2 by Chris Pratt, 16 years ago

Resolution: invalid
Status: closedreopened

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 by Brian Rosner, 16 years ago

Triage Stage: UnreviewedAccepted

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

comment:4 by Malcolm Tredinnick, 16 years ago

Component: Documentationdjango.contrib.admin
Summary: Type: () should be []Admin "fields" and "excludes" should accept both lists and tuples

Changed the title to something less cryptic.

by Julien Phalip, 16 years ago

Attachment: 8899.exclude-tuple.diff added

patch + tests

comment:5 by Julien Phalip, 16 years ago

Summary: Admin "fields" and "excludes" should accept both lists and tuplesAdmin "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 by Daniel Roseman, 16 years ago

Has patch: set

comment:7 by Malcolm Tredinnick, 16 years ago

Resolution: fixed
Status: reopenedclosed

This was fixed in passing in [9086].

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