Opened 19 years ago
Closed 14 years ago
#607 closed enhancement (wontfix)
Admin option to show/hide fields
Reported by: | Wilson Miner | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | |
Severity: | normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Concept: An admin option that specifies a list of fields to show/hide based on the value of another field.
Example: An "I like cake" checkbox that, when checked, shows two previously hidden text fields "Favorite cake" and "Favorite frosting".
Code Example:
admin.switch = [('likes_cake', {'True': ['favorite_cake', 'favorite_frosting']})]
You could also tie this to a particular value of a select field:
admin.switch = [('gender', {'M': ['favorite_sport'], 'F': ['favorite_soap_opera']})]
Unsolved issues:
- Need some place to specify the initial state of the targeted fields (visible or hidden). Default (and most common case) would be hidden, but there are cases where this needs to be reversed.
- All hiding and should happen in javascript, so fields don't get hidden that can't be turned back on with javascript disabled. The switch option could also tie into the validation framework so unnecessary fields (meant to be hidden) don't get filled in even when javascript is off.
- Any other ideas?
Change History (11)
comment:1 by , 19 years ago
comment:2 by , 19 years ago
Description: | modified (diff) |
---|
comment:3 by , 18 years ago
Component: | Admin interface → Translations |
---|---|
milestone: | → Version 1.1 |
Owner: | changed from | to
priority: | normal → highest |
Severity: | trivial → blocker |
Type: | enhancement → defect |
Version: | → magic-removal |
comment:4 by , 18 years ago
Component: | Translations → Admin interface |
---|---|
Owner: | changed from | to
comment:5 by , 18 years ago
priority: | highest → normal |
---|---|
Severity: | blocker → normal |
comment:6 by , 18 years ago
Type: | defect → enhancement |
---|
comment:8 by , 18 years ago
Summary: | IDEA: admin option to show/hide fields → Admin option to show/hide fields |
---|---|
Triage Stage: | Unreviewed → Accepted |
Version: | magic-removal |
And while I'm here, my take on this:
class Person(models.Model): gender = models.CharField(maxlength=1) likes_cake = models.BooleanField() favorite_cake = models.CharField(maxlength=30, blank=True) favorite_sport = models.CharField(maxlength=50, blank=True) favorite_soap = models.CharField(maxlength=50, blank=True) sport_fanatic = models.BooleanField() class Admin: hide_unless = { 'favorite_cake': {'likes_cake': True}, 'favorite_sport': {'gender': 'M'}, 'favorite_soap': {'gender': 'F'}, 'sport_fanatic': {'gender': 'M', 'favorite_sport': True}, }
- Can optionally be matched against a list (eg
'icing': {'favourite_cake': ['carrot', 'banana']}
) - Multiple options (like
sport_fanatic
above) areand
ed, could potentially be passed a list of dictionaries foror
s show_unless
could also be implemented for the more rare "show until" condition
comment:9 by , 17 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
In theory, once newforms-admin lands you'll have a level of customization available which will remove the need for the admin app to directly support this.
comment:10 by , 14 years ago
Resolution: | wontfix |
---|---|
Status: | closed → reopened |
Hi - I'm reopening this because the rationale for closing it was that it would be possible to do with newforms... As far as I can tell this isn't straightforward with the current admin, although I'd be happy to stand corrected.
I can think of a number of use-cases for this, and am about to start very inexpertly hacking the admin page javascript for want of a better solution.
B
comment:11 by , 14 years ago
Resolution: | → wontfix |
---|---|
Status: | reopened → closed |
Please don't just reopen tickets closed by a core developer; bring it up on the django-developers mailing list instead.
This is quite possible to build in a generic and reusable way external to Django, using a ModelForm and/or a ModelAdmin subclass and the forms.Media framework, so there is no need for Django to include it (and if Django ever did include it, it would be because it first got very popular as an external project).
"How" questions should go to #django, django-users, etc.
To be consistent, the examples should both take dictionaries. (And they should take a list, so that you can have more than one switch per admin screen.)
It's a bit syntax heavy, but I like the idea.