Creating a team of users with jobs

I want to make a model where users can create a team of users, and in these teams add the job that they did and choose recipient of the job(that is the member of this team) that they did it for.

I don't how to create a choice field for the recipient of the job.

from django.db import models
from django.contrib.auth.models import User

class Team(models.Model):
    name = models.CharField(max_length=120)
    members = models.ManyToManyField(User)

class Job(models.Model):
    belonging = models.ForeignKey(Team,on_delete=models.CASCADE)
    executor = models.ForeignKey(User,on_delete=models.CASCADE)
    task_description = models.CharField(max_length=180)
    recipient = models.ManyToManyField(Team.members) # <--

It will depend on the logic of your project. If a Job can be used by several users then you need ManyToManyField:

class Job(models.Model):
    recipient = models.ManyToManyField(User) # <--

On the other hand if a Job can be destined to only one user it will be ForeignKey:

class Job(models.Model):
    recipient = models.ForeignKey(User) # <--
Back to Top