django-import-export

Django - Import Export - Upload multiple files

99封情书 提交于 2020-02-25 04:22:30
问题 Im using django import-export module and Im following this documentation: https://simpleisbetterthancomplex.com/packages/2016/08/11/django-import-export.html#importing-data I want to create an upload-page where the user can upload multiple files. This is how far I got: views.py def upload_data(request): if request.method == 'POST': wo_resource = WorkordersResource() pl_resource = PlantResource() se_resource = SeriesResource() re_resource = ResourcesResource() rd_resource =

django-import-export outside admin

China☆狼群 提交于 2020-02-20 11:39:47
问题 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

How to import django-taggit tag in django-import-export

不打扰是莪最后的温柔 提交于 2020-01-25 07:20:26
问题 I can't import Django-taggit tags using Django-import-export. This error is when the value is entered. Line number: 1 - invalid literal for int() with base 10: 'def' Also, this error is when the value is blank. Line number: 2 - Cannot add <QuerySet []> (<class 'django.db.models.query.QuerySet'>). Expected <class 'django.db.models.base.ModelBase'> or str. I also posted question in This issue. xlsx table  there is an id column too. models.py from django.db import models from django.urls import

How to import django-taggit tag in django-import-export

杀马特。学长 韩版系。学妹 提交于 2020-01-25 07:20:26
问题 I can't import Django-taggit tags using Django-import-export. This error is when the value is entered. Line number: 1 - invalid literal for int() with base 10: 'def' Also, this error is when the value is blank. Line number: 2 - Cannot add <QuerySet []> (<class 'django.db.models.query.QuerySet'>). Expected <class 'django.db.models.base.ModelBase'> or str. I also posted question in This issue. xlsx table  there is an id column too. models.py from django.db import models from django.urls import

Django import-export new values in foriegn key model

被刻印的时光 ゝ 提交于 2020-01-24 09:53:45
问题 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 model- it says "matching query does not exist" and will not import the data. How can I tell it to add new object to the foreign key model if they don't exist in the foreign key? Models.py snippet

Django import-export fields

亡梦爱人 提交于 2020-01-16 06:10:43
问题 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 next((s[1] for s in MyModel.STATE_CHOICES if s[0] == status), 'Uknown') I want to import/export some data class MyModelResource(resources.ModelResource): status = fields.Field(column_name='status', attribute=

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

偶尔善良 提交于 2020-01-02 08:46:52
问题 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 explain here. If you modify the dataset in before_import function, it doesn't spread to the preview, preview only display the object of my model class, nothing more... How can I display the name of

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

南笙酒味 提交于 2019-12-31 01:19:06
问题 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 ? 回答1: You can override the get_export_formats() method of the ExportMixin : from import_export.formats import base_formats class MyAdmin(ExportMixin): # your normal stuff def get_export_formats(self): """ Returns available export formats. """ formats = ( base_formats.CSV, base_formats.XLS, base

Foreign Key Mismatch Error with django csv import-export

不羁岁月 提交于 2019-12-25 00:14:01
问题 I'm trying to import three datasets with csv import-export package for three models: service, library and price. I am getting this error when I try to upload a dataset for the service model. Line number: 1 - foreign key mismatch - "catalog_price" referencing "catalog_service" If I try to add price, I get this error. The library model loads fine. Line number: 1 - Service matching query does not exist. models.py There are three models: service, library, and price. class Service(models.Model):

How import a function from another view with Django?

假如想象 提交于 2019-12-24 19:24:13
问题 I have this folder hierarchy: |---- saga |---- core |---- views.py |---- study_time |---- views.py On my study_time/views.py , I have this functions: def study_time(request): def tasks_subjects(week_day, key): #Code here return __tasks def day_studies(week_day): __tasks_subjects = tasks_subjects(week_day, 0) #Code here return __studies return render(request, 'study_time.html', context) On my core/views.py , I need the day_studies() function, so I'm importing like this: from saga.study_time