How to reuse a Django model for multiple relationships

I want to make a task model and a user model. And I want each task to be able to be related to 3 users. Each task should be related to a creator user, an assignee user, and a verifier user. And I want to only have one user table. My inclination is to have 3 foreign keys on the task table: creator_id, assignee_id, and verifier_id. Is this the correct way to do it? How do I model that in Django?

Use 3 Foreignkey on Task model and use related_name to identify each of creator, assigner and verifier

Try something like :

task.creator = user
task.save()

...and so on for an assignee and a verifier

This automatically manages the foreign key relationship properly.

Вернуться на верх