[Answered ]-Django annotate query with values from Many To Many Relationship

1👍

QuerySets 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()])

Leave a comment