Hi all, I wrote a custom field which should get an object by a primary key value (chainId). The base storage type is an int. I have a call that does "obj.save(force_update=True)", and I get this "may not be NULL" error. I set a debug point in execute_sql(), and indeed, it seems to say "UPDATE ... fieldname = NULL, ... WHERE ...". My get_db_prep_value () looks like this:
def get_db_prep_value(self, value): assert isinstance(value.chainId, (int, long)) return value.chainId If anyone has encountered a similar problem, I'd appreciate it. regards, Nicholas class ImmutableRefField(models.Field): __metaclass__ = models.SubfieldBase def __init__(self, typegetter, *argv, **kwargs): self.typegetter = typegetter models.Field.__init__(self, *argv, **kwargs) def get_internal_type(self): return "IntegerField" def to_python(self, value): if isinstance(value, (int, long, str)): clstype = self.typegetter() assert issubclass(clstype, ImmutableModel) return clstype.ReferenceGetter(clstype, value) elif isinstance(value, (ImmutableModel, ImmutableModel.ReferenceGetter)): return value raise NotImplementedError, "unknown value type %r" %(value) # dynamically typed is nice; this could be a reference or an object def get_db_prep_value(self, value): assert isinstance(value.chainId, (int, long)) return value.chainId def get_db_prep_lookup(self, lookup_type, value): if lookup_type == 'exact': return [self.get_db_prep_value(value)] pyhelp = help; import pdb; pdb.set_trace() if lookup_type == 'in': return [force_unicode(v) for v in value] if lookup_type == 'isnull': return [] raise FieldError('Invalid lookup type: %r' % lookup_type) --~--~---------~--~----~------------~-------~--~----~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---