Relate Objects to a choice of objects
|Reported by:||Boffbowsh||Owned by:||Adrian Holovaty|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
I have a object that needs to be related to one of a number objects. I propose two new field types called ForeignChoice and ManyToManyChoice (name suggestions welcomed, because I think they suck to be honest)
from django.core import meta COMPONENT_TYPES = ( TextInput, ColourChoice ) class Component(meta.Model): name = meta.CharField(max_length=32) input = meta.ForeignChoice(COMPONENT_TYPES) class TextInput(meta.Model): text = meta.TextField() class ColourChoice(meta.Model): name = meta.SlugField(primary_key=True) rgb = meta.CharField(max_length=7)
This would create a appname_components table with the id and name fields as you'd expect, but also input_class and input_id fields. input_class would be one of 'TextInput' or 'ColourChoice', and input_id would refer to the PK in that class.
I'll start work on a patch soon, but ideas and comments would be very welcome