私はこのようなモデルを持っています:
from django.contrib.auth.models import User
class Post(models.Model):
title = models.CharField(max_length=255)
content = models.TextField()
followers = models.ManyToManyField(User, null=True, blank=True)
そして今、私の見解では、ログインしたユーザーがその人がフォローしているすべての投稿を閲覧できるようにフィルタリングしたいと考えています。そして問題は、より多くの人が同じ投稿をフォローできることです。
def get_followed_posts(request):
user = request.user
posts = Post.objects.filter(followers__contains=user) # If the user is in the list of followers return the Post.
return render_to_response('post_list.html', {'posts': posts}, context_instance=request_context(request))
これを行う方法はありますか?