Comments (15)
@PetrDlouhy - I can't reproduce it exactly in the way you have it.
- What happens if you declare a
fields
list with the fields you want in the export? - I have a test case here
- I find that if I remove the
fields
declaration, I get all Resource fields in the export. - Are you able to reproduce using this test case?
- I find that if I remove the
from django-import-export.
@matthewhegarty I think, that test is too specific for to test the actual problem. The test runs only ModelResource.export()
, but the problem would probably lie in the admin form handling these field checkboxes:
I expect that it behaves like if the checkbox for a field was not selected.
I will try to investigate further and make the appropriate test.
from django-import-export.
Hi Petr
I tried with your branch but reverted all your changes from resources.py
. I added a new EBook and set the author to "Ian Fleming".
When I export the Ebook, I see:
The export file I get is:
id,Email of the author,name,published_date
1,[email protected],Moonraker 2,2024-05-27
So it's possibly a bug that the Export HTML doesn't show the name of the field name to be exported ("Email of the author"), but other than that it looks ok... Am I missing something?
from django-import-export.
@matthewhegarty I didn't touch that part and I am not sure, which variant is correct. The original field name can be more readable for the user as it is/can be consistent across multiple resources.
I can imagine, that some resources would have totally unreadable column_names, e.g. IDs or legal identifiers.
Maybe we should display both values like Author Email (Email of the author)
.
from django-import-export.
@matthewhegarty I have added that functionality as separate PR #1857. Please check it and decide if you like this style or if I should prefer only one variant.
from django-import-export.
I notice that if I add the attribute name, then the test in #1857 passes:
# test fails
author = fields.Field(column_name="AuthorFooName")
# test passes
author = fields.Field(attribute="author", column_name="AuthorFooName")
This is similar to what was reported here this could be a v4 regression, I'll test in v3.
from django-import-export.
I tested in v3 (added test here). This passes in v3, so we have a regression in v4 when the attribute name is not supplied.
from django-import-export.
@matthewhegarty I don't understand entirely. The test in will pass after applying #1856 (not #1857).
Is there something that needs to be fixed in either of those commits?
But maybe I am missing something, I will look at it tomorrow with fresh mind.
from django-import-export.
Hi, I am still looking into it. I think there are a couple of things going on with other parts of the code which need addressing. I'll write a more detailed response tomorrow.
from django-import-export.
hi Petr
I adapted your changes and made a new PR (#1861). I found that if I set an attribute on the field during initialization, then this resolves the issue without needed to modify resources.py
. I have kept your other changes in.
The reason this works is because the author
field in test_export_fields_column_name
does not contain a defined attribute, therefore it is ignored during export.
This also fixes an issue I uncovered whilst testing (#1860). I propose that I merge this PR instead of yours. What do you think?
from django-import-export.
@matthewhegarty That seems to be a better solution. I tested it and it seems to be working.
The PR is missing the refactoring made in this commit: 9d2cab3
Those changes are unrelated to the PR itself, so it is clear why they are not in the PR (although the commit is and then the changes are reverted, so I suggest it might be better to rebase it out).
I think that the refactoring would be still beneficial for django-import-export
and I can make it in separate PR (after merging #1861), if you think it too.
from django-import-export.
I only removed the change so that I could be sure that changes to resources.py
did not affect the fix in #1861.
There is some duplication in those methods, so feel free to submit a new PR to make the code clearer. I would recommend to hide any shared logic in a protected method.
I also wasn't comfortable with the new Field attribute called original_name
, but we shouldn't need that now due to the change in #1861.
Thanks again for all your help in identifying and fixing this issue π
from django-import-export.
Yeah, the original_name
was only a tool to transfer the field variable name. Since now it is in attribute
we don't need it anymore. I will make the refactor PR after #1861 is merged.
from django-import-export.
@matthewhegarty Everything seems to be working. Thank you very much for your attention and all the work you put into this project.
from django-import-export.
np - thanks for your input!
from django-import-export.
Related Issues (20)
- Fixed Arabic translate for 'Import' word HOT 2
- Breaking change due to _check_import_id_fields HOT 2
- Improve parsing of DateTimeWidget HOT 4
- `TypeError: Widget.__init__() got an unexpected keyword argument 'allow_blank'` HOT 4
- numeric fields exported as text by default since v4 to excel HOT 4
- Customize export format depending on file type
- ModelResource field order in admin import page HOT 5
- How to explicitly disable and enable bulk import? HOT 1
- Widget configuration documentation is unclear
- Related model with primary key causes import exception (regression)
- Setting a string value to None stopped preserving existing data in v4 HOT 6
- The get_export_resource_kwargs() doesn't contain `export_form` in v4, example from docs doesn't work
- Incorrect widget is set for 'declared' fields
- Inconsistent queryset creation when export item pks are stored in form data HOT 2
- One Click Export HOT 3
- Overriding `formats`, `export_formats`, `import_formats` not documented. HOT 1
- How can this work for import when items in the import have FKs to other item in the import? HOT 2
- Enable parallel tests
- unexpected keyword argument 'search_help_text' HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-import-export.