python 2.7 - Django 1.5 class Meta has no attribute 'verbose_name_plural' -
i have upgraded project django1.3 django1.5 getting error "attributeerror: class meta has no attribute 'verbose_name_plural'"
base class
class portalmodelbase(models.base.modelbase): def __new__(cls, name, bases, attrs): attr_meta = attrs.pop('meta', none) try: is_global = attr_meta.is_global del attr_meta.is_global except attributeerror: is_global = false attrs['meta'] = attr_meta model = super(portalmodelbase, cls).__new__(cls, name, bases, attrs) model._meta.is_global = is_global return model class meta: abstract = true
model class
having meta class portalmodelbase
class portalmodel(models.model): __metaclass__ = portalmodelbase name = models.charfield(max_length=255, verbose_name='name*', help_text='enter name', blank=false) description = models.charfield(max_length=1024, verbose_name='description', help_text="enter description", blank=true,null=true, default='') createdby = models.charfield(max_length=128) createdon = models.datetimefield() modifiedby = models.charfield(max_length=128) modifiedon = models.datetimefield() def __init__(self_, *args, **kwargs): log.info("portal model initializing") if kwargs: d = copy.copy(kwargs) key in d: if key not in self_._meta.get_all_field_names(): #the key given dictionary not in model. #django, design, throw exception #this prevents kwargs.pop(key) return super(portalmodel, self_).__init__(*args, **kwargs) class meta: abstract = true
inherited class
class testip(portalmodel): address = models.charfield(max_length=128, verbose_name='vip') class meta: abstract = false verbose_name = 'testip' verbose_name_plural = "testips"
tried call verbose_name_plural in views.py getting error "attributeerror: class meta has no attribute 'verbose_name_plural'"
views.py
kwargs[testip.meta.verbose_name_plural.lower().replace(' ', '')] = table
it works fine in django1.3, please figure out issue.
thanks in advance
i figured out answer
in django1.5 should access meta class 'testip._meta.verbose_name_plural'
i have changed
kwargs[testip.meta.verbose_name_plural.lower().replace(' ', '')] = table
to
kwargs[testip._meta.verbose_name_plural.lower().replace(' ', '')] = table
it works fine in django1.5
Comments
Post a Comment