Hi, i want to use NumericRangeFilter on a field that is added by annotate(), by default this isn't working, but i'm bypassing it with following hack:
class CpuCoresFilter(ListFilter):
# This is a hack to use NumericRangeFilter with custom field.
# We use ListFilter as a base, to bypass django checks (admin.E113)
# And we return NumericRangeFilter with custom field and field_path in __new__.
def __new__(cls, request, params, model, model_admin):
return NumericRangeFilter(
PositiveIntegerField(verbose_name=_("CPU cores (total)")),
request,
params,
model,
model_admin,
field_path="cpu_cores",
)
It works, but i don't think this a good idea in the long run.
Hi, i want to use
NumericRangeFilter
on a field that is added byannotate()
, by default this isn't working, but i'm bypassing it with following hack:It works, but i don't think this a good idea in the long run.
Any ideas how to do this better?