I am using django-import-export in an app of my web project.
The class.py file is as:
class Article(models.Model):
siret = models.CharField(max_length=16)
newspaper = models.CharField(max_length=200)
writer = models.CharField(max_length=1000)
TOPIC_TYPE = (
('Sport', 'Sport'),
('Beauté','Beauté'),
('Food', 'Food'),
('Business', 'Business'),
('Music', 'Music'),
('Art', 'Art'),)
topics = MultiSelectField(choices = TOPIC_TYPE)
Note that topics is a MultiSelectField.
In admin.py I simply followed the django-import-export tutorial, hence:
class ArticleResource(resources.ModelResource):
class Meta:
model = Article
exclude = ('is_true', )
class ArticleAdmin(ImportExportModelAdmin):
resource_class = ArticleResource
admin.site.register(Article, ArticleAdmin)
The issue while importing data is as you guess with the "topics" variable.
I first exported an xlsx file to see the way this variable is exported. This is literally how:
siret ... topics
-----------------------------------
0000068591590 ... Music, Art
0000068591595 ... Business, Beauté
0000068591600 ... Art
The issue, is with data importing.
I simply tried to import back the above exported file, by changing "siret" numbers.
Once imported, in the admin interface, I was surprised, Django laughed at me by selecting only the first topic for each article in the available CheckBoxes (only Music for 0000068591590, only Business for 0000068591595).
Hence I tried to import through:
Music, Art (as exporting way)
['Music','Art']
[Music, Art]
However It's not working.
Ty