我有一個用戶追隨者系統的應用程序,我已經能夠實現,但我嘗試檢索個人用戶追隨者和追隨者,但我無法得到它。下面是我的代碼django用戶追隨者從數據庫檢索
View.py
def following(request):
query = Contact.objects.filter(request.user.following)
context = {
'query': query
}
template = 'following.html'
return render(request, template, context)
Models.py
class Contact(models.Model):
user_from = models.ForeignKey(User,related_name='rel_from_set')
user_to = models.ForeignKey(User,related_name='rel_to_set')
created = models.DateTimeField(auto_now_add=True,db_index=True)
class Meta:
ordering = ('-created',)
def __str__(self):
return '{} follows {}'.format(self.user_from,self.user_to)
User.add_to_class('following',models.ManyToManyField('self', through=Contact,related_name='followers', symmetrical=False))
模板
{% load staticfiles %}
{% block content %}
<h2>following</h2>
<div id="action-list">
<h1>{{ results.get_full_name }}</h1>
</div>
{% endblock %}
附加代碼將根據要求添加。
請提供更多代碼 –
模型是什麼樣的? – Jonathan