Skip to content

Commit 52f2330

Browse files
committed
Revert "attempt at fixing user.get_project_chats"
This reverts commit 97b525d.
1 parent 97b525d commit 52f2330

2 files changed

Lines changed: 10 additions & 15 deletions

File tree

chats/models.py

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

88
from files.models import UserFile
9+
from projects.models import Project
910

1011
User = 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):

users/models.py

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

54
from 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()]

0 commit comments

Comments
 (0)