question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: use verbose_name instead of field name for column names

See original GitHub issue

When your exporting data from your database as xls or csv it’s usually for human reading so it would be nice if the column names would be the verbose_name of the model fields. i.e. “Company name” instead of company_name for a field: company_name = models.CharField(_('Company name'))

As far as i can tell this is not currently possible, even just passing a display_name value to a (custom) field for a resource would be a nice fix…

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:14 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
DurandAcommented, Dec 23, 2015

@gnuhpc here is an updated solution working with Django>=1.9:

def get_export_headers(self):
    headers = []
    for field in self.get_fields():
        model_fields = self.Meta.model._meta.get_fields()
        header = next((x.verbose_name for x in model_fields if x.name == field.column_name), field.column_name)
        headers.append(header)
    return headers
2reactions
waketzhengcommented, Jun 22, 2021

If your resource class have custom field, code can be as follows:

from import_export import resources
from import_export.fields import Field

class VerboseExportMixin:
    """Export with verbose name"""

    def get_export_headers(self):
        vnames = {i.name: i.verbose_name for i in self.Meta.model._meta.fields}
        return [vnames.get(i.split("__")[0], i) for i in super().get_export_headers()]


class MyModelResource(VerboseExportMixin, resources.Resource):
    url = Field(column_name="Activation URL")
   
    class Meta:
        model = MyModel
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to write not field name but verbose name of field in this ...
I may be misinterpreting the question, but if you want to change field.name: for field in opts.fields: field.name = 'Foo'.
Read more >
Reserved Field Names - Amazon Forecast
Amazon Forecast reserves the following names. You can't use these names for your schema fields or dataset headers. A. A. ABORT.
Read more >
verbose_name - Django Built-in Field Validation
A human-readable name for the field. If the verbose name isn't given, Django will automatically create it using the field's attribute name, ...
Read more >
Documentation: 15: psql - PostgreSQL
Specifies the name of the database to connect to. This is equivalent to specifying ... Turn off printing of column names and result...
Read more >
Database Engine events and errors - SQL Server
Too many table names in the query. The maximum allowable is %d. 107, 15, No, The column prefix '%.*ls' does not match with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found