Remove named field from fieldsets

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# Django snippet 1803: http://djangosnippets.org/snippets/1803/

import logging

logger = logging.getLogger(__name__)


def remove_from_fieldsets(fieldsets, fields):
    for fieldset in fieldsets:
        for field in fields:
            if field in fieldset[1]['fields']:
                logging.debug("'%s' field found in %s, hiding." % (field, fieldset[1]['fields']))
                newfields = []
                for myfield in fieldset[1]['fields']:
                    if not myfield in fields:
                        newfields.append(myfield)
                        
                fieldset[1]['fields'] = tuple(newfields)
                logger.debug('Setting newfields to: %s' % newfields)
            
                break

More like this

  1. Initial values for new items in admin by RommeDeSerieux 4 years, 7 months ago
  2. ExtendibleModelAdminMixin by dokterbob 4 years, 5 months ago
  3. Fieldsets for Views by Nad/ 4 years, 2 months ago
  4. DRY Fieldsets by DrMeers 4 years, 10 months ago
  5. Memento by manelvf 3 years, 3 months ago

Comments

(Forgotten your password?)