Hi all, I'm writing a custom field wishing to implement something similar to a multiplechoice. The problem is that when I run syncdb I receive a AttributeError: 'ListField' object has no attribute 'db_column' Any idea?
my models.py is: ------------------------------------------------------------------- from django.db import models from cm.custom.fields import ListField EXAMPLE_CHOICES = ( ('A', 'foo'), ('B', 'bar'), ) class Partner(models.Model): example = ListField(separator=',', choices=EXAMPLE_CHOICES) ------------------------------------------------------------------- ListField is defined by: ------------------------------------------------------------------- from django.db import models from django.core import validators class ListField(models.Field): __metaclass__ = models.SubfieldBase def __init__(self, *args, **kwargs): self.separator = kwargs['separator'] # checking if separator has been carefully chosen for choice in kwargs['choices']: if self.separator in choice[0]: # separator is a character already present in choices, this cannot be raise TypeError('Separator colliding with choices, see choice \'%s\'.' % choice[0]) kwargs['max_length'] = 255 def to_python(self, value): if value is None: if self.null: return value else: raise validators.ValidationError, ugettext_lazy("This field cannot be null.") if type(value) == type([]): pass elif type(value) == type(()): value = list(value) else: value = str(value).split(self.separator) value.sort() return value def get_db_prep_save(self, value): return self.separator.join(value) def get_db_prep_lookup(self, lookup_type, value): if lookup_type == 'exact': return self.get_db_prep_save(self.to_python(value)) elif lookup_type == 'contains': return "%" + "%".join(self.to_python(value)) + "%" elif lookup_type == 'isnull': return [] else: raise TypeError('Lookup type %r not supported.' % lookup_type) ------------------------------------------------------------------- complete error page: ------------------------------------------------------------------- Traceback (most recent call last): File "manage.py", line 11, in <module> execute_manager(settings) File "/usr/lib/python2.5/site-packages/django/core/management/ __init__.py", line 272, in execute_manager utility.execute() File "/usr/lib/python2.5/site-packages/django/core/management/ __init__.py", line 219, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/lib/python2.5/site-packages/django/core/management/ base.py", line 72, in run_from_argv self.execute(*args, **options.__dict__) File "/usr/lib/python2.5/site-packages/django/core/management/ base.py", line 85, in execute self.validate() File "/usr/lib/python2.5/site-packages/django/core/management/ base.py", line 112, in validate num_errors = get_validation_errors(s, app) File "/usr/lib/python2.5/site-packages/django/core/management/ validation.py", line 28, in get_validation_errors for (app_name, error) in get_app_errors().items(): File "/usr/lib/python2.5/site-packages/django/db/models/loading.py", line 126, in get_app_errors self._populate() File "/usr/lib/python2.5/site-packages/django/db/models/loading.py", line 55, in _populate self.load_app(app_name, True) File "/usr/lib/python2.5/site-packages/django/db/models/loading.py", line 70, in load_app mod = __import__(app_name, {}, {}, ['models']) File "/home/jo/lavori/comunità montana mugello/cm/../cm/web/ models.py", line 11, in <module> class Partner(models.Model): File "/usr/lib/python2.5/site-packages/django/db/models/base.py", line 62, in __new__ new_class.add_to_class(obj_name, obj) File "/usr/lib/python2.5/site-packages/django/db/models/base.py", line 184, in add_to_class value.contribute_to_class(cls, name) File "/usr/lib/python2.5/site-packages/django/db/models/fields/ subclassing.py", line 49, in contribute_to_class super(self.__class__, self).contribute_to_class(cls, name) File "/usr/lib/python2.5/site-packages/django/db/models/fields/ __init__.py", line 183, in contribute_to_class self.set_attributes_from_name(name) File "/usr/lib/python2.5/site-packages/django/db/models/fields/ __init__.py", line 179, in set_attributes_from_name self.attname, self.column = self.get_attname_column() File "/usr/lib/python2.5/site-packages/django/db/models/fields/ __init__.py", line 193, in get_attname_column column = self.db_column or attname AttributeError: 'ListField' object has no attribute 'db_column' ------------------------------------------------------------------- --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---