from django.shortcuts import render
from .models import Article, Category

def index(request):
    query = request.GET.get('q')
    if query:
        articles = Article.objects.filter(title__icontains=query) | Article.objects.filter(content__icontains=query)
    else:
        articles = Article.objects.all()
    categories = Category.objects.all()
    context = {
        'articles': articles,
        'categories': categories,
    }
    return render(request, 'core/index.html', context)