Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Column names with spaces #36

Closed
pwr905 opened this issue Jul 14, 2013 · 5 comments
Closed

Column names with spaces #36

pwr905 opened this issue Jul 14, 2013 · 5 comments

Comments

@pwr905
Copy link

pwr905 commented Jul 14, 2013

Can't use column names with spaces - at least, as far as I could tell.

If this is indeed the case, and I'm not just being stupid, the fix is in resources.py at line 299.

    method = getattr(self, 'dehydrate_%s' % field.column_name, None)

becomes

    method = getattr(self, 'dehydrate_%s' % field.column_name.replace(' ', '_'), None)

Current use cases should be unaffected by that change.

@bmihelac
Copy link
Member

Hi, it looks like we should use attribute_name instead of column_name. attribute_name:

method = getattr(self, 'dehydrate_%s' % field.column_name, None)

I have to test this, but would appreciate if you can test that this work for your case.

regards

@pwr905
Copy link
Author

pwr905 commented Jul 15, 2013

That was my initial thought, too, but attribute_name might be blank, and that led me down the road of testing for a value. Given that I wasn't too familiar with the internals of import_export, the replace seemed an easier fix at the time.

Also, the use case for me is generating an export report (of sorts) for non-technical users, and being able to specify the column name in a very verbose way (i.e. more descriptive than what I name my attributes) is a requirement.

@bmihelac
Copy link
Member

@pwr905 I am almost sure that attribute_name should be used in dehydratebut I will have catch some time to dig in code and test it does not break anything.

@bmihelac
Copy link
Member

In https://github.com/bmihelac/django-import-export/compare/fix-36-use-field-name-for-dehydration branch is a change that uses field_name for dehydrating fields.

field_name is assigned when Resource is declared.

Example of use is in tests:

https://github.com/bmihelac/django-import-export/blob/d73c05641eafe52d7904ec0c53737ce195795a00/tests/core/tests/resources_tests.py#L181

Does this solve issue stated above?

@pwr905
Copy link
Author

pwr905 commented Jul 24, 2013

Sorry for the delay, been really busy. Will test it out in the next few days and let you know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants