Added profiles page and friends system

This commit is contained in:
ITQ
2024-03-03 09:20:17 +03:00
parent 13b4e8bafb
commit c81cd3560f
7 changed files with 132 additions and 3 deletions
+11
View File
@@ -32,6 +32,7 @@ class Profile(models.Model):
null=True,
)
image = models.URLField(max_length=200, blank=True, null=True)
friends = models.ManyToManyField("self", blank=True, symmetrical=False)
def __str__(self):
return self.login
@@ -39,6 +40,16 @@ class Profile(models.Model):
def is_authenticated(self):
return True
def add_friend(self, user):
if self != user:
self.friends.add(user)
def remove_friend(self, user):
self.friends.remove(user)
def check_for_friendship(self, user):
return self.friends.filter(pk=user.pk).exists()
@classmethod
def check_unique(cls, user_id, validated_data):
errors = {}