Skip to content

filters

management.filters ¤

Classes¤

FilterVisible(target, model, field=None) ¤

Filter objects the user has permission to view.

Standard filter shows ALL objects available in the database when faced with a ForeignKey field. This filter shows only the objects that appear in the target model objects that the user has permission to view.

If field is None, the name of the model model is used.

Parameters:

Name Type Description Default
target type[Model]

Model containing the objects.

required
model type[Model]

Model of the objects to display.

required
field str | None

Field to filter by. Defaults to None.

None
Source code in management\filters.py
22
23
24
25
26
27
28
def __init__(
    self, target: type[Model], model: type[Model], field: str | None = None
) -> None:
    self.target = target
    self.model = model
    self.field = field or model.__name__.lower()
    self.permission = f"{target._meta.app_label}.view_{target._meta.model_name}"