Questions tagged [django-import-export]

1

votes
0

answer
16

Views

Is there a generic way to implement column names?

I'm trying to implement the django-import-export library in a generic way. When setting the fields property in the Meta class there isn't a way to set the column names. When setting a Field() on the ModelResource directly it is possible. But as far as I know, you can't create those in a generic way....
user3488657
0

votes
0

answer
4

Views

fix error KeyError: 'id' in import_export django package while importing excel file

i am trying to import excel file into sqlite 3 database using import_export package in django. excel file consiste of 2 columns : id:(empty values) name:(contains values) its not working and display the below error: Errors Line number: 1 - 'id' None, smugling Traceback (most recent call last): File...
Django Dg
1

votes
2

answer
297

Views

How to get request in ModelResource django-import-export

How to get request.user from method queryset of ModelResource in django-import-export? class PeopleResource(ModelResource): class Meta: model = People exclude = ('id','agent', 'public_id', 'active') def dehydrate_placeA(self, people): ... ... def get_queryset(self): query = People.objects.filter( .....
aldyahsn
1

votes
4

answer
1k

Views

Django import-export fields

I have a short question about django-import-export. In my model I have choice list: STATE_CHOICES = ((NEW_STATE, u'New'), (DELIVERED_STATE, u'Delivered'), (LOST_STATE, u'Lost'), And method that handles mapping choices for names @staticmethod def get_status_name_by_status(status): return ne...
hebius
2

votes
2

answer
4.7k

Views

Django Import/Export to multiple Models (foreignkey)

This has been asked several times- but none of the solutions worked for me. The code below works (in that there are no errors) but it does not see anything to import new data to the foreign key class. It will only import data if it already exists in the foreign key. Does that make sense? Models.py (...
Ycon
2

votes
1

answer
1.8k

Views

Dealing with import of foreignKeys in django-import-export

I don't understand how django-import-export module deals with ForeignKeys. Here is a simple exemple : models.py class TFamilies(models.Model): id_fam = models.AutoField(primary_key=True, unique=True) name_fam = models.CharField(max_length=1024, blank=True,verbose_name='Famille') class TGenus(models...
HydrUra
2

votes
2

answer
3.2k

Views

How do I import data using Django-Import-Export?

The documentation for django-import-export is a bit weak on how to configure the admin to import from a spreadsheet. Does anyone have a full example?
seddonym
2

votes
1

answer
1.7k

Views

Django Admin import_export module used for custom IMPORT

I was trying to follow official doc of import-export: https://django-import-export.readthedocs.org/en/latest/import_workflow.html#import-data-method-workflow But I still do not know how to glue it to my admin assuming that: I want only subset of fields (I created Resource model with listed fields, b...
andilabs
3

votes
2

answer
1.4k

Views

Django-import-export - export from model's functions?

For a Django model I'm using django-import-export package. The manual says I can export fields that are not existing in the target model like so: from import_export import fields class BookResource(resources.ModelResource): myfield = fields.Field(column_name='myfield') class Meta: model = Book http:...
Alveoli
4

votes
1

answer
1.3k

Views

Django import-export importing data with object relationships

I've been playing with django import-export because it seems to be the obvious choice for anything import/export related in django and it's fantastic. Trouble is I can't find much in the way of docs on the import side of things and I'd like to be able to use it to import data through and cope with t...
markwalker_
4

votes
3

answer
359

Views

Extending the admin import form for django import_export

I'm using Django import_export to implement CSV upload in my admin pages. Now I have one model, that contains a foreign key column, but the foreign key column will have only one value for each import. Therefore I would like to allow the user to choose the related model instance from a drop-down inst...
Jarno
1

votes
1

answer
551

Views

Django import-export generate username before user csv upload

I need to bulk generate users for my app from a csv file. The csv I have contains the following fields: last_name, first_name, email To generate the username I have a function which I was hoping to use in a 'dehydrate' method. The dehydrate method works only with exports, not imports. [edit] After...
jcuot
1

votes
1

answer
448

Views

oscarcommerce catalogue import

I have a magento2 project. I want to import product catalog in magento 2 into django oscarcommerce. The official documentaion explains an importer (http://django-oscar.readthedocs.io/en/releases-1.1/howto/importing_a_catalogue.html). But that they are not supporting because its buggy. I tried to fig...
Arun SS
3

votes
3

answer
1.6k

Views

Django import-export: only export

I'm using the third party library Django-import-export for importing/exporting data. It's working properly but I only want the export functionality (not import one). How could I use only export without import?
loar
2

votes
2

answer
851

Views

Django import-export new values in foriegn key model

I'm using the django import-export library to data. It works well except I cannot get it to import objects which don't already exist in the foreign key. If the objects (values in the csv) exist in the foreign key model- then it imports fine. But if the objects/values don't exist in the foreign key m...
Ycon
2

votes
1

answer
456

Views

How do I import tags using django-import-export?

I want to import certain fields as django-taggit tags, using django-import-export. How do I do this?
seddonym
1

votes
1

answer
800

Views

How to have only CSV, XLS, XLSX options in django-import-export?

I have implemented django-import-export for my project. It provides me many file format options by default fro both import and export. How to restrict the file formats to only CSV, XLS and XLSX ?
Gautam Mandewalker
1

votes
1

answer
646

Views

django-import-export override not working

I am overriding the django-import-export resource's methods. But only parent methods are executed. models.py class Model(models.Model): modelField1 = models.CharField( modelField2... modelField3... admin.py class ModelResource(resources.ModelResource): def before_import(self, dataset, using_transac...
Aswin Kumar K P
2

votes
0

answer
254

Views

django-import-export import multiple files

I am using django-import-export library to import several excel books. However, I have over 1,000 books that need to be imported into the db. Is there a way to select a folder to upload instead of selecting and uploading each individual file? I've worked through the tutorial found here: https://djan...
icomefromchaos
2

votes
2

answer
1.8k

Views

Import CSV to Django Model

I have CSV file backed up from my django model with django-import-export,I want to restore that to my model how can i do that ? When i want to create object for each of them i have problem with foreign keys. id,name,address,job,KBSE 1,Hamid,3,Doctor,4311 2,Ali,7,Artist,5343 3,Reza,2,Singer,5232
itmard
2

votes
2

answer
256

Views

Denormalising relationships with django-import-export

I have room booking application with a Booking model that has a simple ForeignKey relationship to my Room model. Here's a super-brief idea of what I'm dealing with: class Room(..): floor = models.IntegerField() number = models.IntegerField() ... class Booking(..): room = models.ForeignKey('Room') .....
Oli
7

votes
1

answer
2.9k

Views

Django-import-export - import of advanced fields?

For a Django model I'm using django-import-export package. If need to export more then just available model fields, like properties or custom fields, new can be added with import_export.fields.Field class and optionally dehydrate_ method. from import_export import resources, fields, instance_loaders...
David Unric
2

votes
0

answer
232

Views

django-import-export get resource field not present in model

According django-import-export Docs we can add fields to Resource that they are not present in target model. So, I have next Resource: class FamilyResource(resources.ModelResource): code = fields.Field(attribute='code', widget=widgets.CharWidget()) parent = fields.Field() class Meta: model = Family...
ekth0r
5

votes
2

answer
1.1k

Views

Django import export Line number: 1 - u"Column 'id' not found

I am trying to import excel documents into a Django DB. I have added the following code to admin.py and model.py. There seems to be an error in the development of Django. I have read through several different documentations about how to fix this error. But I am still a little lost on how to implemen...
icomefromchaos
2

votes
0

answer
188

Views

Installing django-import-export raises ValueError

I'm trying to install django-import-export. Python version = 3.6 Django version = 1.10.3 When I entered: pip install django-import-export It says: raise ValueError("cannot use LOCALE flag with a str pattern") ValueError: cannot use LOCALE flag with a str pattern Thanks in advance.
GG WordPress
2

votes
1

answer
1.3k

Views

Foreign Key in django migration using django-import-export

I'm using django-import-export to load csv files in a migration file which I understand is current best practise for Django 1.7 to load initial data. This worked fine for the first file: class Country(models.Model): ISO2 = models.CharField(max_length=2, primary_key=True) name = models.CharField(max...
PhoebeB
2

votes
2

answer
656

Views

Django-import-export change/remove records absent in uploaded file against db

I'm using Django-import-export module in my admin panel. I import .csv file extracted from our ERM system which updates records in Django myapp database. Everything works like a charm, except that when some records are removed from ERM and are not present in .csv datadump, no updates will be done in...
Trm
2

votes
0

answer
131

Views

django-import-export how to merge/append instead of update for specific fields

I was able to get access to the new row data and existing instance by overriding import_obj. def import_obj(self, instance, row, dry_run): super(RelationshipResource, self).import_obj(instance, row, dry_run) for field in self.get_fields(): if isinstance(field.widget, widgets.ManyToManyWidget): tags...
fishhead
3

votes
0

answer
383

Views

django-import-export: how to specify reference model outside of xls

i have a model (e.g. book) which has a foreign key to another (e.g. author) i want to import all book's of an author in one xls file. is there a way to add a normal django foreign key widget alongside file input and apply the selected key to all of imported rows? bonus question: is this possible to...
pajooh
3

votes
2

answer
791

Views

Django Import - Export: IntegrittyError when trying to insert duplicate record in field(s) with unique or unique_together constraints

Update I have filed a feature request. The idea is to pass on the IntegrittyError produced by the database when unique or unique_together reject a record that already exists in the database. I have the following model: class Compositions(models.Model): composer_key = models.ForeignKey( Composer, ) c...
raratiru
3

votes
0

answer
471

Views

Is-it possible to customize the template of preview in django import-export?

My admin side will be used by no-sys-admin persons so I would like it to be as clear as possible. I don't understand how can I customize the preview before confirming import. To add objects with foreign key reference I juste look for id that matches in before_import function and replace it as it's...
HydrUra
3

votes
1

answer
1.2k

Views

django-import-export can not get it working

Can not get this to do anything, installed, added to apps, followed the docs. nothing. here's my admin.py: from import_export import resources from import_export.admin import ImportExportModelAdmin class EmailGroupResource(resources.ModelResource): class Meta: model = EmailGroup class EmailGroupAdm...
joeskru
2

votes
0

answer
84

Views

Export data from model with reverse foreign key

I'm trying to export a model 'Class' with all the models that are related. Exporting the teacher's data with the ForeignKeyWidget worked. But how do I get the data (name, age) of all students into the export? Models: class Teacher(model.Model): Name = models.CharField(max_length=100) Age = models.Po...
PirateWorm
2

votes
0

answer
60

Views

Exporting using django-import-export and showing verbose names of related objects

I was having a look at the following library - django-import-export. However, I am having issues with exporting with friendly/verbose column names for related objects. Related link: https://github.com/django-import-export/django-import-export/issues/52 class HumanModelResource(resources.ModelResourc...
Aero Chocolate
2

votes
0

answer
43

Views

django-import-export How to format the exported excel's cell?

Is there any way I can format the exported excel file? When i export the files, the column is too small to fit the words. Im quite new to this so any help would be much appreciated. If django-import-export is unable to do this, then is there any other methods to export database information as excel...
Jeremy Hang
2

votes
3

answer
1.2k

Views

Django: import-export && Grappelli

I was using Django import-export app and now I want to add Grappelli in order to improve the Admin interface. I'm getting an error related to the templates. Any suggestion to get them work together? Error: Environment: Request Method: GET Request URL: http://localhost:8000/admin/db_personal/personal...
loar
3

votes
1

answer
503

Views

django-import-export outside admin

I am trying to implement a simple xls file import and save to a model using django-import-export. Unfortunately the docs only cover the admin integration. I am stuck here in my example code: class UploadFileForm(forms.Form): file = forms.FileField() class ExportSpec(resources.ModelResource): class M...
caliph
2

votes
1

answer
1.1k

Views

django admin display field from related model

I would like to display the ip_address from Hosts model in HostInfo's admin display. # models.py class Hosts(models.Model): host_name = models.CharField(max_length=200, unique=True) ip_address = models.GenericIPAddressField(protocol='both', unpack_ipv4=True) def __unicode__(self): return unicode(se...
Simply Seth
7

votes
3

answer
3.9k

Views

Adding foreignKey widget to django-import-export

I'm trying to import data to one of my models, but it's failing because I'm trying to upload the foreignKey Id, not the iterated number that import-export creates. models.py from django.db import models from import_export import resources class School(models.Model): name = models.CharField(max_lengt...
JonnyD
2

votes
1

answer
260

Views

Tmpfile error with django-import-export on Heroku

I am using django-import-export to process CSV files uploaded to my Django admin site. When I run Django on my local machine, all works fine. When I deploy my application to Heroku I start getting errors related to tmpfile access: Feb 24 14:35:12 test-staging app/web.3: ERROR 2017-02-24 22:35:12,14...
deadcode

View additional questions