I\'m creating a news website which has two models:
BestNews has a foreign key of News.
News stand
all_news = News.objects.all().order_by('-pk')
to
all_news = News.objects.filter(select_news__isnull=True).order_by('-pk')
free advice:
change
bestnews1 = Best.objects.filter(select_reason="左一")[0].select_news
to
bestnews1 = Best.objects.filter(select_reason="左一").first()
bestnews1_new = None if bestnew1 is None else bestnews1.select_news
return render(request, 'index.html', {
'all_news': news,
'bestnews1_new':bestnews1_new,
'bestnews2_new':bestnews2_new,
})