Nick, Maybe only your print isn´t working. Look at this class:
http://code.djangoproject.com/browser/django/trunk/django/db/models/fields/__init__.py#L982 If you really want to check if it is working, do: fp = open("/writable/path/to/log.txt", "w") class ForeignKeyWithZeros(models.ForeignKey): """ A ForeignKey, but when the id is 0 the relation is considered to be NULL Use with null=True """ def __get__(self, instance, *args, **kwargs): # never gets called fp.write("Instance %r " % instance) def to_python(self, value): # never gets called fp.write("to_python %r" % value) def __del__(self): fp.close() It´s justa guess. Not sure if it´s going to work. Cheers -- Rui On Mon, Jul 7, 2008 at 4:14 PM, Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > > I'm adapting a legacy database for use with Django and I've come > across a problem I haven't been able to solve! > > The database has ForeignKey fields which are sometimes 0, meaning > there is no related row in the other table. If this database used > NULL instead of 0 then I could use ForeignKey(Other, null=True) and > all would work fine, but it doesn't and I can't change it. > > I've tried lots of different ways of making an adaptor to change the 0 > into a None when read from the database but I haven't made it work (or > even get called!) yet - can anyone give me a clue? > > I'm trying to subclass ForeignKey but none of the methods I override > (except __init__) seem to ever get called! > > Eg ... > > class ForeignKeyWithZeros(models.ForeignKey): > """ > A ForeignKey, but when the id is 0 the relation is considered to be NULL > > Use with null=True > """ > def __get__(self, instance, *args, **kwargs): > # never gets called > print "Instance %r " % instance > > def to_python(self, value): > # never gets called > print "to_python %r" % value > > I'm using svn of few days ago. > > Thanks > > Nick > -- > Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected] 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 -~----------~----~----~----~------~----~------~--~---

