If I create a ForeignKey relationship between two M
odels with null=True, the Admin seems to still insist on there being a foreign object to link to.
For example, I created a very simple ForeignKey relationship from Things to Types:
from django.db import models
class Type(models.Model):
name = models.CharField(max_length=30)
class Thing(models.Model):
type_of_thing = models.ForeignKey(Type, null=True)
name = models.CharField(max_length=30)
In the console, I can happily create Type-less Things:
>>> from ni.models import *
>>> x = Thing()
>>> x.type = None
>>> x.save()
>>> all_things = Thing.objects.all()
>>> print all_things
[<Thing: Thing object>]
>>> print all_things[0].type_of_thing
None
In the Admin, however, when I try to add a new Thing, or even edit and save the existing Thing, the type_of_thing field is shown as required and saving without setting it causes "This field is required." to be displayed and the Thing not to be saved.
Am I doing something wrong?