I'll try to describe my problem with a simple example. Say I have items of type Item
and every item relates to a certain type of Category
. Now I can take any two items and combine into an itemcombo of type ItemCombo
. This itemcombo relates to a certain category called ComboCategory
. The ComboCategory
is based on which categories the items relate to, therefore I'm not to keen on hardcoding the combocategory
in ItemCombo
in case the items categories would change. Can I somehow make combocategory
a virtual field in ItemCombo
that evaluates just in time?
class Category(models.Model):
value = models.CharField(max_length=1)
class Item(models.Model):
value = models.CharField(max_length=10)
category = models.ForeignKey(Category)
class ComboCategory(models.Model):
category1 = models.ForeignKey(Category)
category2 = models.ForeignKey(Category)
value = models.CharField(max_length=1)
class ItemCombo(models.Model):
item1 = models.ForeignKey(Item)
item2 = models.ForeignKey(Item)
combocategory = models.ForeignKey(ComboCategory)