friendship

This commit is contained in:
Egor Matveev
2021-12-19 18:17:46 +03:00
parent a4d272bdfe
commit 52b09cd692
7 changed files with 124 additions and 2 deletions

View File

@@ -8,3 +8,4 @@ from Main.models.solution import Solution
from Main.models.extrafile import ExtraFile
from Main.models.progress import Progress
from Main.models.solution_file import SolutionFile
from Main.models.friendship import Friendship

View File

@@ -0,0 +1,8 @@
from django.contrib.auth.models import User
from django.db import models
class Friendship(models.Model):
from_user = models.ForeignKey(User, on_delete=models.CASCADE, related_name="from_friendship")
to_user = models.ForeignKey(User, on_delete=models.CASCADE, related_name="to_friendship")
verified = models.BooleanField(default=False)

View File

@@ -1,5 +1,8 @@
from functools import cached_property
from django.contrib.auth.models import User
from django.db import models
from django.db.models import Q
from django.utils import timezone
from Main.models.set import Set
@@ -28,6 +31,13 @@ class UserInfo(models.Model):
def has_favourite_language(self):
return self.favourite_language_id is not None
@cached_property
def friends(self):
return User.objects.filter(
Q(to_friendship__to_user=self, to_friendship__verified=True)
| Q(from_friendship__from_user=self, from_friendship__verified=True)
)
@property
def favourite_language(self):
if not self.has_favourite_language: