A "init() got an unexpected keyword argument 'help_text'" exception is raised if the following custom model field is used. The problem arises whenever formfield() is called by a ModelForm subclasses.
from django.contrib.localflavor.it.forms import *
from django.db import models
from django.utils.translation import ugettext_lazy as _
class ITSocialSecurityNumberModelField(models.CharField):
"""
The Italian "Codice Fiscale" (CF) model field.
"""
def formfield(self, **kwargs):
defaults = { 'form_class': ITSocialSecurityNumberField }
defaults.update(kwargs)
return super(ITSocialSecurityNumberModelField, self).formfield(**defaults)
def __init__(self, *args, **kwargs):
defaults = { 'max_length': 16 }
defaults.update(kwargs)
super(ITSocialSecurityNumberModelField, self).__init__(*args, **defaults)
The problem is that most of the IT localflavor form field do not handle help_text. Instead, they pass along args/kwargs. Here is an example traceback from my own code:
Traceback:
File "/Users/phretor/ve/edilges/src/django/django/core/handlers/base.py" in get_response
80. response = middleware_method(request)
File "/Users/phretor/ve/edilges/src/django/django/middleware/common.py" in process_request
56. if (not _is_valid_path(request.path_info) and
File "/Users/phretor/ve/edilges/src/django/django/middleware/common.py" in _is_valid_path
142. urlresolvers.resolve(path)
File "/Users/phretor/ve/edilges/src/django/django/core/urlresolvers.py" in resolve
307. return get_resolver(urlconf).resolve(path)
File "/Users/phretor/ve/edilges/src/django/django/core/urlresolvers.py" in resolve
220. for pattern in self.url_patterns:
File "/Users/phretor/ve/edilges/src/django/django/core/urlresolvers.py" in _get_url_patterns
249. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Users/phretor/ve/edilges/src/django/django/core/urlresolvers.py" in _get_urlconf_module
244. self._urlconf_module = import_module(self.urlconf_name)
File "/Users/phretor/ve/edilges/src/django/django/utils/importlib.py" in import_module
35. __import__(name)
File "/Users/phretor/ve/edilges/src/django-edilges-tip/edilges/urls.py" in <module>
5. admin.autodiscover()
File "/Users/phretor/ve/edilges/src/django/django/contrib/admin/__init__.py" in autodiscover
57. import_module("%s.admin" % app)
File "/Users/phretor/ve/edilges/src/django/django/utils/importlib.py" in import_module
35. __import__(name)
File "/Users/phretor/ve/edilges/src/django-cantiere-tip/cantiere/admin.py" in <module>
21. admin.site.register(Dipendente, DipendenteAdmin)
File "/Users/phretor/ve/edilges/src/django/django/contrib/admin/sites.py" in register
94. validate(admin_class, model)
File "/Users/phretor/ve/edilges/src/django/django/contrib/admin/validation.py" in validate
23. validate_base(cls, model)
File "/Users/phretor/ve/edilges/src/django/django/contrib/admin/validation.py" in validate_base
213. check_formfield(cls, model, opts, 'fields', field)
File "/Users/phretor/ve/edilges/src/django/django/contrib/admin/validation.py" in check_formfield
340. fields = fields_for_model(model)
File "/Users/phretor/ve/edilges/src/django/django/forms/models.py" in fields_for_model
186. formfield = formfield_callback(f, **kwargs)
File "/Users/phretor/ve/edilges/src/django/django/forms/models.py" in <lambda>
162. def fields_for_model(model, fields=None, exclude=None, widgets=None, formfield_callback=lambda f, **kwargs: f.formfield(**kwargs)):
File "/Users/phretor/ve/edilges/src/django-profields-tip/profields/localflavor/it/fields.py" in formfield
33. return super(ITProvinceSelectModelField, self).formfield(**defaults)
File "/Users/phretor/ve/edilges/src/django/django/db/models/fields/__init__.py" in formfield
581. return super(CharField, self).formfield(**defaults)
File "/Users/phretor/ve/edilges/src/django/django/db/models/fields/__init__.py" in formfield
468. return form_class(**defaults)
Exception Type: TypeError at /admin
Exception Value: __init__() got an unexpected keyword argument 'help_text'
You have given an example that talks about ITSocialSecurityNumberField, but then your stack trace talks about ITProvinceSelectModelField. I can't reproduce the any problem like the one you describe with the ITSocialSecurityNumberField and help_text.
I can, however, find a problem with max_length and min_length handling. I'll accept the ticket on that basis.