On Thu, Jun 19, 2008 at 6:21 PM, TiNo <[EMAIL PROTECTED]> wrote: > Hi, > > (Django version 0.97-pre-SVN-7633) > > I am trying to use a custom modelfield. When I try to ad an entry in > the admin, i get: > > --------------------------------------------------------------- > TypeError at /admin/klanten/klant/add/ > __init__() got an unexpected keyword argument 'is_required' > > Traceback: > File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ > site-packages/django/core/handlers/base.py" in get_response > 82. response = callback(request, *callback_args, > **callback_kwargs) > File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ > site-packages/django/contrib/admin/views/decorators.py" in _checklogin > 62. return view_func(request, *args, **kwargs) > File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ > site-packages/django/views/decorators/cache.py" in _wrapped_view_func > 44. response = view_func(request, *args, **kwargs) > File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ > site-packages/django/contrib/admin/views/main.py" in add_stage > 253. manipulator = model.AddManipulator() > File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ > site-packages/django/db/models/manipulators.py" in __init__ > 70. > self.fields.extend(f.get_manipulator_fields(self.opts, self, > self.change)) > File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ > site-packages/django/db/models/fields/__init__.py" in > get_manipulator_fields > 352. return [man(field_name=field_names[i], **params) for i, > man in enumerate(field_objs)] > > Exception Type: TypeError at /admin/klanten/klant/add/ > Exception Value: __init__() got an unexpected keyword argument > 'is_require > ------------------------------------------------------------------------- > > the modelfield is defined as: > > > ----------------------------------------------------------------------------- > from django.db.models import * > from django.contrib.localflavor.nl import forms as nlforms > from django.core import validators > from django.newforms.fields import EMPTY_VALUES > from django.utils.encoding import smart_unicode > from django import oldforms > import re > > phone_re = re.compile('^\+?\d+$') > > class NLPhoneNumberField(Field): > > def get_internal_type(self): > return "CharField" > > def db_type(self): > return "char(16)" > > def to_python(self, value): > if field_data in EMPTY_VALUES: > return u'' > > phone_nr = re.sub('[\-\s\(\)]', '', value) > > if not phone_re.search(p): > raise validation.ValidationError('Ongeldig telefoon > nummer. Voer (evt. +<landcode>) 10 cijfers in.') > > if len(phone_nr) == 12: > if phone_nr[:3] == '+31': > phone_nr = phone_nr[3:] > else: > return phone_nr > elif len(phone_nr) != 10: > raise validation.ValidationError('Ongeldig telefoon > nummer. Voer (evt. +<landcode>) 10 cijfers in.') > > if phone_nr[0] == '6': > return '06 ' + phone_nr[1:] > else: > return '%s %s' % (phone_nr[:3],phone_nr[3:]) > > def get_manipulator_field_objs(self): > return [nlforms.NLPhoneNumberField] > > def formfield(self, **kwargs): > defaults = {'form_class': nlforms.NLPhoneNumberField, > 'max_length':16} > defaults.update(kwargs) > return super(NLPhoneNumberField, self).formfield(**defaults) > ------------------------------------------------------------------------ > > The field is then used in a model without any arguments. > > The problem disappears when I change: > ------------------------------------------------------------------------ > def get_manipulator_field_objs(self): > return [nlforms.NLPhoneNumberField] > ------------------------------------------------------------------------ > to: > ------------------------------------------------------------------------ > def get_manipulator_field_objs(self): > return [oldforms.TextField] > ------------------------------------------------------------------------ >
What is nlforms.NLPhoneNumberField? It sounds like it is a custom newforms-type form field to go with your model field? But get_manipulator_field_objs is an oldforms-type thing and isn't going to work when handed a newforms custom field. Have you considered trying the newforms-admin branch? There admin will be using newforms instead of oldforms so you won't have to get the oldforms stuff working for your custom model field, just newforms. Karen --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---