Admin¶
shopkit.core.utils.admin
-
class
shopkit.core.utils.admin.
LimitedAdminInlineMixin
¶ Bases:
object
InlineAdmin mixin limiting the selection of related items according to criteria which can depend on the current parent object being edited.
A typical use case would be selecting a subset of related items from other inlines, ie. images, to have some relation to other inlines.
Use as follows:
class MyInline(LimitedAdminInlineMixin, admin.TabularInline): def get_filters(self, obj): return (('<field_name>', dict(<filters>)),)
-
get_filters
(obj)¶ Return filters for the specified fields. Filters should be in the following format:
(('field_name', {'categories': obj}), ...)
For this to work, we should either override get_filters in a subclass or define a filters property with the same syntax as this one.
-
get_formset
(request, obj=None, **kwargs)¶ Make sure we can only select variations that relate to the current item.
-
static
limit_inline_choices
(formset, field, empty=False, **filters)¶ This function fetches the queryset with available choices for a given field and filters it based on the criteria specified in filters, unless empty=True. In this case, no choices will be made available.
-