django-import-export

Foreign key widget finds more than 1 value, how should i approach this

我只是一个虾纸丫 提交于 2019-12-08 18:38:27
I am using django-import-export library and I am trying to implement ForeignKey widget which is available to lookup related objects using Author.name instead of Author.pk. Now, the here is the tricky part for the given calendar year I only have one author with the same name, however, next year the author name will be similar. When i try to import, of course, it brings the issue saying that more than Author.name was found. Is there a suggestion to solve the issue? I've used before_save_instance() to do something similar to this. Here's some pseudo-code for how this might work: class

Foreign key widget finds more than 1 value, how should i approach this

南笙酒味 提交于 2019-12-08 03:56:44
问题 I am using django-import-export library and I am trying to implement ForeignKey widget which is available to lookup related objects using Author.name instead of Author.pk. Now, the here is the tricky part for the given calendar year I only have one author with the same name, however, next year the author name will be similar. When i try to import, of course, it brings the issue saying that more than Author.name was found. Is there a suggestion to solve the issue? 回答1: I've used before_save

Django Admin import_export module used for custom IMPORT

邮差的信 提交于 2019-12-08 02:34:44
问题 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, but It crashes while importing anyway with: KeyError full stack bellow. Where - in which method - in my admin class (inheriting of course ImportExportModelAdmin and using defined resource_class )

Django Import/Export to multiple Models (foreignkey)

[亡魂溺海] 提交于 2019-12-07 23:13:15
问题 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 (snippet) ... class Store(models.Model): store_name = models.CharField(max_length=30) def __unicode__(self): return self.store_name #etc class Product(models.Model): Store = models.ForeignKey(Store)

django-import-export to export User model

筅森魡賤 提交于 2019-12-07 14:41:17
问题 I'm using the django-import-export library with success to provide a data download option via the django admin for some of my defined models. I'm having difficulty however providing the same export option via the User Admin. For my other models I've done something like the following to my admin.py : class OtherResource(resources.ModelResource): class Meta: model = Other class OtherAdmin(ExportMixin, admin.ModelAdmin): # Other admin definition here My problem is providing the same Export

Django Import/Export to multiple Models (foreignkey)

删除回忆录丶 提交于 2019-12-06 09:39:06
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 (snippet) ... class Store(models.Model): store_name = models.CharField(max_length=30) def __unicode__(self): return self.store_name #etc class Product(models.Model): Store = models.ForeignKey(Store) Category = models.ForeignKey(Category) first_name = models.CharField(max_length=30) second_name =

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

一世执手 提交于 2019-12-06 02:49:45
问题 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 implement it exactly. In the Trace it keeps saying that my excel document needs an id field. There is no id field in my excel docs nor did I tell my model to look for an id field. The documentation that I

django-import-export to export User model

非 Y 不嫁゛ 提交于 2019-12-05 22:44:00
I'm using the django-import-export library with success to provide a data download option via the django admin for some of my defined models. I'm having difficulty however providing the same export option via the User Admin. For my other models I've done something like the following to my admin.py : class OtherResource(resources.ModelResource): class Meta: model = Other class OtherAdmin(ExportMixin, admin.ModelAdmin): # Other admin definition here My problem is providing the same Export functionality to pre-packaged Django models like User . I tried the following... class UserResource

Foreign Key in django migration using django-import-export

倖福魔咒の 提交于 2019-12-05 21:06:21
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_length=50, unique=True) and the entire migration file contents. note that ISO2 is the primary key so required the addition line import_id_fields = ['ISO2']. Code adapted from answer to this question: Loading initial data with Django 1.7 and data migrations : from django.conf import settings import

django-import-export outside admin

痴心易碎 提交于 2019-12-04 13:57:20
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 Meta: model = Specialty view: def ca_import(request): if request.method == 'POST' and 'import_test' in request.POST: form = UploadFileForm(request.POST, request.FILES) if form.is_valid(): filehandle = request.FILES['file'] dataset = ??? result = ExportSpec().import_data(dataset, dry_run=False, raise