def gallery_async(request):
    # Maybe refactor this into existing views and check request.is_ajax?
    media_type = request.GET.get('type', 'image')
    term = request.GET.get('q')
    media_locale = request.GET.get('locale', settings.WIKI_DEFAULT_LANGUAGE)
    if media_type == 'image':
        media_qs = Image.objects
    elif media_type == 'video':
        media_qs = Video.objects
    else:
        raise Http404

    media_qs = media_qs.filter(locale=media_locale)

    if term:
        media_qs = media_qs.filter(Q(title__icontains=term) |
                                   Q(description__icontains=term))

    media = paginate(request, media_qs, per_page=ITEMS_PER_PAGE)

    return render(request, 'gallery/includes/media_list.html', {
        'media_list': media})
AJAX endpoint to media gallery.
dataset/ETHPy150Open mozilla/kitsune/kitsune/gallery/views.py/gallery_async