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
- Bind Administration by ashcrow 4 years, 9 months ago
- Modifying the fields of a third/existing model class by marinho 2 years, 5 months ago
- DRY Fieldsets by DrMeers 4 years ago
- Signal to post new saved objects to Twitter by arthurfurlan 4 years, 3 months ago
- Human readable file names decorator by maxk 2 years, 2 months ago
Comments