def visitor_ban_action(modeladmin, request, queryset): for ip in [iptoint(x) for x in queryset.values_list('ip', flat=True)]: try: IPBan.objects.get(ip=ip) except IPBan.DoesNotExist: ban = IPBan(ip=ip) ban.save()
def ban(self, request, object_id, action=None): visitor = get_object_or_404(Visitor, pk=object_id) ip = iptoint(visitor.ip) if action is True: try: IPBan.objects.get(ip=ip) except IPBan.DoesNotExist: ban = IPBan(ip=ip) ban.save() else: IPBan.objects.filter(ip=ip).delete() return redirect(request.META.get('HTTP_REFERER', '../..'))