Answer the question
In order to leave comments, you need to log in
How to be C or B views.py?
Good afternoon!
Trouble again.
class NewsPageView(ListView):
model = News
# template_name =news.html
def get_template_names(self, **kwargs):
qs = Model.objects.filter(site=self.request.site)
for data in qs:
if data.template_site == '1':
return 'news1.html'
else:
return 'news.html'
def get_queryset(self, **kwargs):
return News.objects.on_site(site=self.request.site)
def get(self, request, *args, **kwargs):
result = News.objects.on_site(site=self.request.site)
if request.GET:
query = request.GET.get("q")
result = result.filter(Q(title__icontains=query)|Q(short_text__icontains=query)|Q(text__icontains=query))
return render(request, self.template_name, {'news': result})
Answer the question
In order to leave comments, you need to log in
return render(request, self.get_template_names(*args), {'news': result})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question