About Admin List Filter with Options Limited to Existing Relations

Django provides an ability to show related items in the list filter only if they are connected to this model instances:

1
2
3
4
5
6
7
8
9
from django.contrib import admin
from django.contrib.admin import RelatedOnlyFieldListFilter
from .models import Post

@admin.register(Post)
class PostAdmin(admin.ModelAdmin):
    list_filter = [
        ("categories", RelatedOnlyFieldListFilter),
    ]

Programming Development Django 4.2 Django 3.2 Django 2.2