1👍
✅
QuerySet
s are immutable, this thus means that .prefetch_related
creates a new QuerySet
, you thus work with:
class ArticleAdmin(admin.ModelAdmin):
list_display = ['publication_titles']
def get_queryset(self, request):
return super().get_queryset(request).prefetch_related('publications')
def publication_titles(self, obj):
return ', '.join([pub.title for pub in obj.publications.all()])
Source:stackexchange.com