Skip to content

Instantly share code, notes, and snippets.

View hovi's full-sized avatar

Karel Hovorka hovi

View GitHub Profile
@hovi
hovi / django-admin-get-changelist.py
Created October 30, 2019 12:52
change changelist url in django admin as simple as possible (usable with proxies)
from urllib import urlencode
from django.contrib.admin.views.main import ChangeList
from django.urls import reverse
def change_admin_url(model, **kwargs):
class CustomModelChangeList(ChangeList):
def url_for_result(self, obj):
return model_change_url_only(obj, model._meta, **kwargs)
@hovi
hovi / listlinksmixin.py
Last active August 24, 2020 07:20 — forked from Vigrond/listlinksmixin.py
A Django Admin Mixin that supports foreign key and many-to-many relationship links with list_display_fk_clickthrough and list_display_m2m_clickthrough attribute
class ListDisplayClickthroughMixin(object):
list_display_fk_clickthrough = []
list_display_m2m_clickthrough = []
def __init__(self, *args, **kwargs):
super(ListDisplayClickthroughMixin, self).__init__(*args, **kwargs)
for field in self.list_display_fk_clickthrough or []:
self.bind_field(field, fk_link_fnc)
for field in self.list_display_m2m_clickthrough or []:
//Adapter for RecyclerView, that displays contents of kotlin data class using reflection (or in theory just public properties of a class).
import kotlin.reflect.KClass
import kotlin.reflect.KProperty1
import kotlin.reflect.KVisibility
import kotlin.reflect.full.memberProperties
val <T : Any> KClass<T>.publicProperties: Collection<KProperty1<T, *>>
get() = memberProperties.filter { it.visibility == KVisibility.PUBLIC }