Skip to content

Commit 97b525d

Browse files
committed
attempt at fixing user.get_project_chats
1 parent 6d69332 commit 97b525d

2 files changed

Lines changed: 15 additions & 10 deletions

File tree

chats/models.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from django.db import models
77

88
from files.models import UserFile
9-
from projects.models import Project
109

1110
User = get_user_model()
1211

@@ -87,7 +86,7 @@ class ProjectChat(BaseChat):
8786

8887
id = models.PositiveIntegerField(primary_key=True, unique=True)
8988
project = models.ForeignKey(
90-
Project, on_delete=models.CASCADE, related_name="project_chats"
89+
"projects.Project", on_delete=models.CASCADE, related_name="project_chats"
9190
)
9291

9392
def get_users(self):

users/models.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from django.contrib.auth.models import AbstractUser
22
from django.db import models
3+
from chats.models import ProjectChat
34

45
from users.constants import (
56
ADMIN,
@@ -133,14 +134,19 @@ def calculate_ordering_score(self) -> int:
133134
score += 7
134135
return score
135136

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
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
144150

145151
def get_key_skills(self) -> list[str]:
146152
return [skill.strip() for skill in self.key_skills.split(",") if skill.strip()]

0 commit comments

Comments
 (0)