Export Excel from Django with verbose names

Question:

I am using DjangoObjectActions from django_object_actions package that adds an action in Django Admin to export my Querys model to excel.

class QueryAdmin(DjangoObjectActions, admin.ModelAdmin):
    def export_to_xls(self, request, obj):
        query_record = Query.objects.all().values('profile__full_name')
        return excel.make_response_from_records(
            query_record,
            'xlsx',
            file_name="Querys"
        )

    list_display = ('weight', 'height')
    export_to_xls.label = "Export to Excel"
    changelist_actions = ('export_to_xls',)

I could not find how to export my table with columns’ verbose names. I found how to just get the verbose names of columns but is there a way to export them to excel?

I need it because verbose names are in different language and that would be really great to show columns titles like that.

Would be grateful for any help!

Answers:

I did not find a way to export it in Excel as I wanted. As a solution I made a custom page in my Django Admin with custom table that I made with Javascript lib DataTables – (https://datatables.net). This lib helps to create tables with buttons to export to excel, csv and many other features.

UPDATE:

I also added this lines of code to my Profiles model:

    def __str__(self):
        return self.full_name

This code returns string that is exactly rendered as the display name of instances for that model. So now in my another model that is connected by foreign key profile column shows users full name.

Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.