Skip to content

Instantly share code, notes, and snippets.

Haki Benita hakib

Block or report user

Report or block hakib

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
hakib /
Created Dec 9, 2017
Django Admin InputFilter
# common/
class InputFilter(admin.SimpleListFilter):
template = 'admin/input_filter.html'
def lookups(self, request, model_admin):
# Dummy, required to show the filter.
return ((),)
def choices(self, changelist):
hakib /
Last active Nov 2, 2019
Custom django checks using Django check framework, inspect and ast.
Custom django checks.
H001: Field has no verbose name.
H002: Verbose name should use gettext.
H003: Words in verbose name must be all upper case or all lower case.
H004: Help text should use gettext.
H005: Model must define class Meta.
H006: Model has no verbose name.
H007: Model has no verbose name plural.
hakib /
Last active Dec 6, 2019
CountTimeoutLimitPaginator - Paginator that enforced a timeout on the count operation.
class TimeLimitedPaginator(Paginator):
Paginator that enforced a timeout on the count operation.
When the timeout is reached a "fake" large value is returned instead,
Why does this hack exist? On every admin list view, Django issues a
COUNT on the full queryset. There is no simple workaround. On big tables,
this COUNT is extremely slow and makes things unbearable. This solution
is what we came up with.
import pytest
def A():
return 1
def B():
return 1
from typing import Iterator, Dict, Any, Optional
from urllib.parse import urlencode
import datetime
#------------------------ Profile
import time
hakib /
Last active Jan 28, 2020
How to Turn Django Admin Into a Lightweight Dashboard
from django.contrib import admin
from django.db.models import Count, Sum, Min, Max, DateTimeField
from django.db.models.functions import Trunc
from . import models
def get_next_in_date_hierarchy(request, date_hierarchy):
hakib /
Created Feb 12, 2020
from django.db import models
class Theater(models.Model):
class Meta:
verbose_name = 'Theater'
verbose_name_plural = 'Theaters'
name = models.CharField(max_length=50)
You can’t perform that action at this time.