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?
UPDATE
Here's my simplified models
class User(models.Model):
id = models.CharField(primary_key=True, max_length=100)
name = models.CharField(max_length=100)
class Task(models.Model):
id = models.CharField(primary_key=True, max_length=100)
title = models.CharField(max_length=100)
creator = models.ForeignKey('User', on_delete=models.DO_NOTHING, related_name='creator_tasks')
assignee = models.ForeignKey('User', on_delete=models.DO_NOTHING, related_name='user_tasks')
verifier = models.ForeignKey('User', on_delete=models.DO_NOTHING, related_name='verifier_tasks')
And here's the error I get when I relate a user to a task as a creator and try to get the task's creator:
$ python manage.py shell
>>> from todoapp.models import User
>>> from todoapp.models import Task
>>> user = User.objects.get(id='1')
>>> task = Task.objects.get(id='1')
>>> task.creator_id = user.id
>>> task.save()
>>> task.creator
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Users/josh/.venv/myenv/lib/python3.9/site-packages/django/db/models/fields/related_descriptors.py", line 188, in __get__
raise self.RelatedObjectDoesNotExist(
todoapp.models.Task.creator.RelatedObjectDoesNotExist: Task has no creator.
UserandTaskobjects created?