11from django .contrib .auth import get_user_model
22from django .db import models
3+ from django .db .models import UniqueConstraint
34
45from industries .models import Industry
56from projects .helpers import VERBOSE_STEPS
67from projects .managers import ProjectManager , AchievementManager
8+ from users .models import CustomUser
79
810User = get_user_model ()
911
@@ -22,7 +24,6 @@ class Project(models.Model):
2224 industry: A ForeignKey referring to the Industry model.
2325 presentation_address: A URLField presentation URL address.
2426 image_address: A URLField image URL address.
25- collaborators: A ManyToManyField collaborators of the project.
2627 leader: A ForeignKey referring to the User model.
2728 draft: A boolean indicating if Project is a draft.
2829 datetime_created: A DateTimeField indicating date of creation.
@@ -45,12 +46,6 @@ class Project(models.Model):
4546 presentation_address = models .URLField (blank = True )
4647 image_address = models .URLField (blank = True )
4748
48- collaborators = models .ManyToManyField (
49- User ,
50- related_name = "projects" ,
51- blank = True ,
52- )
53-
5449 leader = models .ForeignKey (
5550 User ,
5651 on_delete = models .SET_NULL ,
@@ -105,3 +100,39 @@ def __str__(self):
105100 class Meta :
106101 verbose_name = "Достижение"
107102 verbose_name_plural = "Достижения"
103+
104+
105+ class Collaborator (models .Model ):
106+ """Project collaborator model
107+
108+ Attributes:
109+ user: A ForeignKey referencing the user who is collaborating in the project
110+ project: A ForeignKey referencing the project the user is collaborating in
111+ role: A CharField meaning the role the user is fulfilling in the project
112+ datetime_created: A DateTimeField indicating date of creation.
113+ datetime_updated: A DateTimeField indicating date of update.
114+ """
115+
116+ user = models .ForeignKey (CustomUser , models .CASCADE , verbose_name = "Пользователь" )
117+ project = models .ForeignKey (Project , models .CASCADE , verbose_name = "Проект" )
118+ role = models .CharField ("Роль" , max_length = 1024 , blank = True , null = True )
119+
120+ datetime_created = models .DateTimeField (
121+ verbose_name = "Дата создания" , null = False , auto_now_add = True
122+ )
123+ datetime_updated = models .DateTimeField (
124+ verbose_name = "Дата изменения" , null = False , auto_now = True
125+ )
126+
127+ class Meta :
128+ verbose_name = "Коллаборатор"
129+ verbose_name_plural = "Коллабораторы"
130+ constraints = [
131+ UniqueConstraint (
132+ fields = [
133+ "project" ,
134+ "user" ,
135+ ],
136+ name = "unique_collaorator" ,
137+ )
138+ ]
0 commit comments