I am following the instructions at the bottom of this page
http://docs.djangoproject.com/en/dev/topics/db/models/#inheritance-and-reverse-relations
and here
http://docs.djangoproject.com/en/dev/ref/models/fields/#onetoonefield
I have a parent class Directory and a child classes Business, Tourism
and Community. The child classes have a subcategory that I want to be
able to access from a listing of Directory. My reading of the
documentation was that by defining a onetoone field with
parent_link=True I could do this, but on going into Admin and trying
to add a new entry to Business I immediately get the error Cannot
assign None: "Business.id" does not allow null values.
Where is my error (again......):
class Directory(models.Model):
name = models.CharField(max_length=60)
...
class Business(Directory):
id = models.OneToOneField(Directory, parent_link=True,
related_name="entries")
cat = models.ForeignKey(Subcategory, limit_choices_to =
{'category__exact': 2})
And the SQL table it created, which looks correct to me:
CREATE TABLE `town_business` (
`id_id` int(11) NOT NULL,
`cat_id` int(11) NOT NULL,
PRIMARY KEY (`id_id`),
KEY `town_business_cat_id` (`cat_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Or am I trying to be too clever all together? This is the query that
does everything except pull in the cat from the subclass.
entries = Directory.objects.filter(is_live=True).select_related
().distinct()