我有这段代码:
PersonList(LoginRequiredMixin, ListView)
model = Person
paginate_by = 10
如何在ListView中修改此函数以适应装饰器?
我试试:
var htmltext='test message <a class="red pagtag" href="#" contenteditable="false">Harshvardhan Rane</a> test <br> <a class="red pagtag" href="#" contenteditable="false">Jay Alvarrez</a>';
var $html = $("<div/>").html(htmltext);
$html.find("a").each(function() {
$(this).replaceWith("**"+$(this).text()+"**");
});
$("body").append($html)
我不知道如何实现上面提到的装饰器。
答案 0 :(得分:0)
Engraçado,sófuncionoudesse jeito。
from django.utils.decorators import method_decorator
class SuperuserRequiredMixin(object):
@method_decorator(user_passes_test(lambda u: u.is_authenticated() and u.is_superuser))
def dispatch(self, *args, **kwargs):
return super(SuperuserRequiredMixin, self).dispatch(*args, **kwargs)
class PersonList(SuperuserRequiredMixin, ListView):
model = Person
paginate_by = 20