views:

24

answers:

2

Hi, I want to design a Task model that can be associated to Project Models, another X model, and other Task models. The obvious choice is a foreign key, but I want any particular instance of that Task model to only be associated to only one of those model types, that is, if a Task model has a relationship with a Project model, it cannot have a relationship with another Task model, and so on. Any advice in what would be the best way to represent this? Thanks.

A: 

Have a look at Generic relation. It lets you define a foreign key on multiple models. This way your task is only linked to one of your models.

Eric Fortin
A: 

What I have done is to inherit from a base class on all my models that will be related to tasks. Task models points to that base class on the ForeignKey with unique=True, and it seems like all subclasses inherit the relationship. Thanks.