# -*- coding: utf-8 -*- from django.http import HttpResponseRedirect from django.shortcuts import get_object_or_404 from models import Banner, update_views, update_clicks def preview(request, id): """Редиректит на баннер с заданным id - для админки.""" return show(request, id, inc_views=False) def show(request, id, inc_views=True): """Редиректит на баннер с заданным id и обновляет статистику просмотров. Для preview из админки статистику просмотров можно отключить. """ obj = get_object_or_404(Banner, pk=id) if inc_views: update_views(obj.pk) return HttpResponseRedirect(obj.pic.url) def click(request, id): """Редиректит на url перехода и обновляет статистику кликов.""" obj = get_object_or_404(Banner, pk=id) update_clicks(obj.pk) return HttpResponseRedirect(obj.dest_url)