I want to create a minimalist task management app to learn Django’s basics. So there will be Projects , Tasks and Users as the three big entities.
- A Project can have multiple users
- A Project can have multiple tasks
- A task can be assigned to 1 user
I can unable to figure out how to do a Many-to-One from Project – > Users using django.contrib.auth.models.User as my Users source.
This is what I have so far, but I know it is wrong and I am unable to wrap my head around it. I tried to relate to other questions such as the one with Contestents and the one with Vulnerabilities URLS on StackOverflow. I am not sure if I have to write my own User Model, or somehow extend it.
class Project(models.Model):
Project_Name = models.CharField(max_length=100)
Project_Users = models.ManyToManyField(User)
class Tasks(models.Model):
Task_Name = models.CharField(max_length=300)
Task_AssignedToUser = models.ForeignKey("Project_Name", through=Users)
Thank you for your help.
Get the the users participating in a specific project:
Get a project’s tasks:
Get All the tasks a user has, of all the projects:
Notes:
A
ForeignKeyis a Many to One relationship. e.g. A Task belongs to only one Project – A Project can have many Tasks.You don’t need superfluous field names.
nameis better thanProject_NameOne question at a time.