class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
friends = models.ManyToManyField(User, blank=True, related_name='friends')
slug = models.SlugField(unique=True, blank=True)
updated_date = models.DateTimeField(auto_now=True)
created_date = models.DateTimeField(auto_now_add=True)
{% for friend in profile.friends.all %}
{{ friend }}
{% endfor %}
def get_friends_list(self):
return self.user.friends.all()
{% for friend in profile.get_friends_list %}
{{ friend }}
{% endfor %}
def permission_create_post(user):
if user.is_authenticated:
profile = Profile.objects.get(user=user)
if user.profile.slug == profile.slug:
return True
else:
return False
{% if permission_create_post %}
<p>some text...</p>
{% endif %}