Reference¶
Links¶
- django_admin_helpers.links.admin_add_url(model: type[Model]) str
Get the URL to the admin add for a model.
- django_admin_helpers.links.admin_link_tag(instance: Model | None, label: StrOrPromise | None = None) SafeString
Make a link to a model instance in the admin.
- django_admin_helpers.links.admin_list_url(model: type[Model] | Model) str
Get the URL to the admin change list for a model.
- django_admin_helpers.links.admin_url(instance: Model) str
Get the URL to a model instance in the admin.
- django_admin_helpers.links.get_app_model_names(model: Model | type[Model]) tuple[str, str]
Get app label and model name from private meta attribute.
- django_admin_helpers.links.inline_button(url: str, label: StrOrPromise, mt: str = '0', mb: str = '1rem') str
Build a button to be inlined in the admin.
- django_admin_helpers.links.link_tag(url: str, label: StrOrPromise | None = None, blank: bool = False) SafeString
Build an HTML tag for a hyperlink.
Mixins¶
- class django_admin_helpers.mixins.FilesDeleteMixin
Mixin for
ModelAdminclasses to delete files along with model instances.By default, Django leaves the files of
FileField(andImageField) in storage when the model instances referencing them are deleted. This mixin hooks into the admin deletion flow to also delete the files from storage, both when deleting a single instance from its change page and when using the bulk delete action from the change list.Set the
file_field_namesattribute to the list of file field names to delete (defaults to["file"]):class DocumentAdmin(FilesDeleteMixin, admin.ModelAdmin): file_field_names = ["file", "thumbnail"]
If a file cannot be deleted, the error is logged and the instance is deleted from the database anyway.
- delete_model(request: HttpRequest, obj: Model) None
Delete the file(s) associated with the instance.
- delete_queryset(request: HttpRequest, queryset: QuerySet) None
Delete the file(s) associated with the instances in the queryset.