Admin integration
django-queryable-properties comes with an integration in Django’s admin, allowing to use queryable properties in
various places in both ModelAdmin
subclasses and inlines.
To properly get queryable properties to work with certain features of admins/inlines, django-queryable-properties
offers specialized base classes that can be used instead of Django’s regular base classes:
queryable_properties.admin.QueryablePropertiesAdmin
in place of Django’s ModelAdminqueryable_properties.admin.QueryablePropertiesStackedInline
in place of Django’s StackedInlinequeryable_properties.admin.QueryablePropertiesTabularInline
in place of Django’s TabularInline
For more complex inheritance scenarios, there is also the
queryable_properties.admin.QueryablePropertiesAdminMixin
, which can be added to both admin and inline classes
to enable queryable properties functionality while using different admin/inline base classes.
The following table shows the admin/inline options that queryable properties may be referenced in and whether or not
each feature requires the use of one of the specialized base classes mentioned above.
Queryable properties may be refenced via name in either the listed admin/inline class attributes or in the result of
their corresponding get_*
methods (although there is a special case for get_list_filter
as described in
Dynamically generating list filters below).
Admin/inline option |
Requires special class |
Restrictions/Remarks |
---|---|---|
|
No |
|
|
No |
|
|
No |
|
|
Yes |
|
|
Yes |
|
|
Yes |
|
|
No |
|
|
No |
|
|
No |
|
Dynamically generating list filters
Whenever the list filters are to be determined dynamically by overriding get_list_filter
, proper handling of
queryable property items may be disabled as this is also implemented by overriding get_list_filter
.
Therefore, it is important either invoke the queryable property processing by either generating the base filters
using a super
call:
from queryable_properties.admin import QueryablePropertiesAdmin
class MyAdmin(QueryablePropertiesAdmin):
def get_list_filter(self, request):
list_filter = super(MyAdmin, self).get_list_filter(request)
# ... process the list filter sequence ...
# Note: queryable property entries have been replaced with custom callables at this point.
return list_filter
… or by utilizing the admin method
queryable_properties.admin.QueryablePropertiesAdminMixin.process_queryable_property_filters()
to postprocess a
custom generated filter sequence:
from queryable_properties.admin import QueryablePropertiesAdmin
class MyAdmin(QueryablePropertiesAdmin):
def get_list_filter(self, request):
list_filter = []
# ... generate the list filter sequence ...
# Utilize process_queryable_property_filters to handle queryable property filters correctly.
return self.process_queryable_property_filters(list_filter)