朋友们,我正在使用django-friendship来实现用户跟随我的应用程序。我试图弄清楚如何知道当前登录的用户是否跟随另一个用户。我在models.py中使用自定义函数。
models.py
class UserProfile(models.Model):
user = models.OneToOneField(User,unique=True)
designation= models.CharField(max_length=32,choices=DESIGNATION,default="student", null=True)
faculty = models.CharField(max_length=32,choices=FACULTIES, default="bridge", null=True)
rep = models.IntegerField(default=0)
image_off = models.BooleanField(default=False)
scripts_off = models.BooleanField(default=False)
picture = models.ImageField(upload_to='profile_images', blank=True)
# find out if the user is followed by current user
def is_followed(self,*args):
follows = Follow.objects.follows(self.user,*args)
if follows:
return True
else:
return False
和我的模板
{% for u in users %}
{% if not u.userprofile.is_followed request.user %}
<a href="{% url 'follow' u.username %}">Follow</a>
{% endif %}
{% endfor %}
我哪里错了?帮帮我朋友。