verbose_name in custom model Fields

Create issue
Issue #1239 resolved
Valentin Gorbunov created an issue

while debugging our project with haystack ( http://haystacksearch.org/ ) we found that some model Fields has bug with //verbose_name//.

for example, one of that:

{{{ #!python shipping_model = ShippingChoiceCharField(_("Shipping Models"), max_length=30, blank=True, null=True) }}}

but definition of //ShippingChoiceCharField// is:

{{{ #!python

class ShippingChoiceCharField(models.CharField):

def __init__(self, choices="__DYNAMIC__", *args, **kwargs):
    if choices == "__DYNAMIC__":
        kwargs['choices'] = shipping_choices()

    super(ShippingChoiceCharField, self).__init__(*args, **kwargs)

}}}

so argument //_("Shipping Models")// catched as //choices// and then super class get //kwargs// without //verbose_name//.

for example:

{{{ #!python

class CharField(Field): description = _("String (up to %(max_length)s)")

def __init__(self, *args, **kwargs):

    if self.__class__.__name__ == "ShippingChoiceCharField":
        log.debug(self.__class__.__name__)
        log.debug(args)
        log.debug(kwargs)
    super(CharField, self).__init__(*args, **kwargs)
    self.validators.append(validators.MaxLengthValidator(self.max_length))

}}}

shows that //verbose_name// was lost {{{ DJANGO_DB_MODELS_FIELDS DEBUG ShippingChoiceCharField DJANGO_DB_MODELS_FIELDS DEBUG () DJANGO_DB_MODELS_FIELDS DEBUG {'max_length': 30, 'null': True, 'blank': True} }}}

Comments (4)

  1. Log in to comment