我的文字帖子在添加通知功能之前可以正常工作,但是现在还不能,我有一个调试打印,但是我没有看到帖子对象,而是看到发布了该帖子的用户。除了获取帖子ID,timesince
和notify函数外,我没有做任何其他更改,我对图片和视频帖子使用了完全相同的方法,并且它们可以正常工作,因此,我。我在通知功能中进行了调试打印,以确保正确输入了帖子类型和ID,并且确实显示了ID和类型
views.py
@login_required()
def text_post(request):
if request.method == "POST":
form = TextPostForm(request.POST)
if form.is_valid():
t_post = form.save(commit=False)
t_post.author = request.user
t_post.save()
id = t_post.id
time = timesince
print(t_post) # t_post shows the user instead of the post
followers = list(request.user.followers.all())
notify(followers,
request.user,
f"{request.user.username} posted {time}",
id,
'text'
)
print(t_post)
#redirect to last page
return redirect('home')
else:
form = TextPostForm()
post_type = 'text'
return render(request, 'create_post.html', {'form': form, 'post_type': post_type})
forms.py
class TextPostForm(forms.ModelForm):
class Meta:
model = TextPost
fields = ('description','privacy', 'categories')