File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66from django .db import models
77
88from files .models import UserFile
9+ from projects .models import Project
910
1011User = get_user_model ()
1112
@@ -86,7 +87,7 @@ class ProjectChat(BaseChat):
8687
8788 id = models .PositiveIntegerField (primary_key = True , unique = True )
8889 project = models .ForeignKey (
89- "projects. Project" , on_delete = models .CASCADE , related_name = "project_chats"
90+ Project , on_delete = models .CASCADE , related_name = "project_chats"
9091 )
9192
9293 def get_users (self ):
Original file line number Diff line number Diff line change 11from django .contrib .auth .models import AbstractUser
22from django .db import models
3- from chats .models import ProjectChat
43
54from users .constants import (
65 ADMIN ,
@@ -134,19 +133,14 @@ def calculate_ordering_score(self) -> int:
134133 score += 7
135134 return score
136135
137- def get_project_chats (self ):
138- # collaborations = self.collaborations.prefetch_related(
139- # "project__project_chats"
140- # ).all()
141-
142- # return queryset of project chats
143- return ProjectChat .objects .filter (
144- project__collaborations__user_id = self .id
145- ).distinct ()
146- # projects = []
147- # for collaboration in collaborations:
148- # projects.extend(list(collaboration.project.project_chats.all()))
149- # return projects
136+ def get_project_chats (self ) -> list :
137+ collaborations = self .collaborations .prefetch_related (
138+ "project__project_chats"
139+ ).all ()
140+ projects = []
141+ for collaboration in collaborations :
142+ projects .extend (list (collaboration .project .project_chats .all ()))
143+ return projects
150144
151145 def get_key_skills (self ) -> list [str ]:
152146 return [skill .strip () for skill in self .key_skills .split ("," ) if skill .strip ()]
You can’t perform that action at this time.
0 commit comments