[Django]-Django-import-export export also related field of a model


When you declare your resource, it is possible to follow Model relationships (docs)

Declare a resource (with fields) (taken from the example app):

class BookResource(ModelResource):

    class Meta:
        model = Book
        fields = ('author__name',)

Reference the resource in your Admin class:

class BookAdmin(ImportExportMixin, admin.ModelAdmin):
    list_display = ('name', 'author', 'added')
    list_filter = ['categories', 'author']
    resource_class = BookResource


Follow this guide in django-import-export docs

Avanced Data Manipulation on Export

It will walk you through exporting related fields of any model.

Leave a comment