第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何在模板中僅過濾我的朋友帖子

如何在模板中僅過濾我的朋友帖子

楊魅力 2023-09-05 20:35:59
我是 django 的新手,正在嘗試構(gòu)建社交網(wǎng)絡(luò)系統(tǒng)。在我看來,我正在使用配置文件變量導(dǎo)入我的朋友列表?,F(xiàn)在我只想顯示我朋友的帖子。但無法制定如何過濾所有帖子的邏輯。對(duì)于每種方法我都會(huì)遇到不同類型的錯(cuò)誤。這是觀點(diǎn):@login_requireddef post_comment_create_and_list_view(request):    profile = Profile.objects.select_related('user').get(user=request.user).get_all_friends_list()    #profile contains list of the friends i have        queryset = Post.objects.all_posts().filter(author__icontains=profile.values())        #post form    post_form = PostModelForm()    if 'submit_p_form' in request.POST:        post_form = PostModelForm(request.POST or None, request.FILES or None)        if post_form.is_valid():            instance = post_form.save(commit=False)            instance.author = profile            instance.save()            post_form = PostModelForm()            messages.success(request, 'Post published')            return redirect('posts:main_post_list')        #comment form    comment_form = CommentModelForm()    if 'submit_c_form' in request.POST:        comment_form = CommentModelForm(request.POST or None)        if comment_form.is_valid():            instance = comment_form.save(commit=False)            instance.user = profile            post_id = request.POST.get('post_id')            instance.post = Post.objects.get(id=post_id)            instance.save()            comment_form = CommentModelForm()            return redirect('posts:main_post_list')    context = {        'queryset': queryset,        'profile': profile,        'post_form': post_form,        'comment_form': comment_form,    }    return render(request, 'posts/main.html', context)這是帖子模型:class PostManager(models.Manager):    def all_posts(self):        posts = Post.objects.prefetch_related('author',"comment_posted__user",            "comment_posted__user__user",'likes')                    return posts我想要應(yīng)用的邏輯是從我的朋友列表中獲取所有帖子。并非來自每個(gè)用戶。我應(yīng)該使用什么方法
查看完整描述

1 回答

?
炎炎設(shè)計(jì)

TA貢獻(xiàn)1808條經(jīng)驗(yàn) 獲得超4個(gè)贊

請(qǐng)更正post_comment_create_and_list_view中的author_in:

queryset = Post.objects.all_posts().filter(author__in=profile)


查看完整回答
反對(duì) 回復(fù) 2023-09-05
  • 1 回答
  • 0 關(guān)注
  • 125 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)