Decouple 'help_text' attribute from field definition

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# readable_models.py

from django.db.models.base import ModelBase as DjangoModelBase

class ModelBase(DjangoModelBase):
    ''' Decouples 'help_text' attribute from field definition. '''
    def __new__(cls, name, bases, attrs):
        help_text = attrs.pop('HelpText', None)
        new_cls = super(ModelBase, cls).__new__(cls, name, bases, attrs)
        if help_text:
            for field in new_cls._meta.fields:
                field.help_text = getattr(help_text, field.name, field.help_text)
        return new_cls

More like this

  1. DRY Fieldsets by DrMeers 2 years, 8 months ago
  2. Human readable file names decorator by maxk 10 months, 2 weeks ago
  3. Modifying the fields of a third/existing model class by marinho 1 year, 1 month ago
  4. Bind Administration by ashcrow 3 years, 5 months ago
  5. Exists Filter OneToOneField in Admin by davidvaz 3 months ago

Comments

(Forgotten your password?)