Django application and library for importing and exporting data with admin integration.

Overview

django-import-export

Build status on Travis-CI https://coveralls.io/repos/github/django-import-export/django-import-export/badge.svg?branch=master Current version on PyPi Documentation

PyPI - Python Version

PyPI - Django Version

django-import-export is a Django application and library for importing and exporting data with included admin integration.

Features:

  • support multiple formats (Excel, CSV, JSON, ... and everything else that tablib support)
  • admin integration for importing
  • preview import changes
  • admin integration for exporting
  • export data respecting admin filters

docs/_static/images/django-import-export-change.png

Example app

To run the demo app:

cd tests
./manage.py makemigrations
./manage.py migrate
./manage.py createsuperuser
./manage.py loaddata category book
./manage.py runserver

Contribute

If you'd like to contribute, simply fork the repository, commit your changes to the develop branch (or branch off of it), and send a pull request. Make sure you add yourself to AUTHORS.

As most projects, we try to follow PEP8 as closely as possible. Please bear in mind that most pull requests will be rejected without proper unit testing.

Comments
  • Better surfacing of validation errors in UI / optional model instance validation

    Better surfacing of validation errors in UI / optional model instance validation

    Hi @bmihelac,

    Related issues:

    • #64
    • #176
    • #415
    • #601

    Here's where I've got to so far. I thought it would be good to get some feedback before getting stuck into writing new tests, but the current ones are passing, so at least nothing is broken :)

    When enabled, instance.full_clean() is called for each row, and any resulting validation errors surface themselves in the preview table like so:

    screenshot 2018-11-02 at 15 35 37

    The errors are hidden visually at first, then become visible when you hover over a row's first column, in such a way that it doesn't hide any of the values for the current row. It's pretty crude, but it's a starting point. Some examples:

    screenshot 2018-11-02 at 15 35 42 screenshot 2018-11-02 at 15 35 53

    Anyone wanting to give this a whirl for themselves should be able to install from git using:

    pip install git+https://github.com/ababic/[email protected]

    Any/all feedback welcome :)

    opened by ababic 43
  • when import csv file ,KeyError: u'id' occured

    when import csv file ,KeyError: u'id' occured

    i try to import some data form csv file, but errors occurred as follows:

    Errors Line number: 1 - u'id' Traceback (most recent call last): File "/home/zhijiasun/.virtualenvs/tutorial/local/lib/python2.7/site-packages/import_export/resources.py", line 317, in import_data instance, new = self.get_or_init_instance(instance_loader, row) File "/home/zhijiasun/.virtualenvs/tutorial/local/lib/python2.7/site-packages/import_export/resources.py", line 149, in get_or_init_instance instance = self.get_instance(instance_loader, row) KeyError: u'id'

    I just modify the data of the csv file which exported by the app and then try to import it. But error happed.

    stale 
    opened by zhijiasun 36
  • question:UnicodeDecodeError at /admin/blog/author/import/

    question:UnicodeDecodeError at /admin/blog/author/import/

    Sir,thanks a lot to develop this great repository. I have little problem to solve , as below the code:

    #in models.py
    class Author(models.Model):
        author = models.CharField('作者', max_length=50)
        title = models.CharField('标题', max_length=150)
        qualification = models.ForeignKey(Qualification)
        mark = models.ManyToManyField(Mark)
        blog = models.TextField('博客内容')
        time = models.DateField('写作日期')
    
        def __unicode__(self):
            return unicode(self.author)
    
        class Meta:
            ordering = ['time']
    
    #in admin.py
    class AuthorAdmin(ImportExportModelAdmin, admin.ModelAdmin):
        search_fields = ('author', 'title', 'mark', 'blog')
        list_display = ('author', 'title', 'time')
    

    When I export the data, 1 but the csv file appear to be the retortion, 2 when I modified the second row author data and import,

    3 it cause the error, 4

    how I it be smoothly modified and import?thanks. Allenlee

    opened by hebijiandai 31
  • CLI import (reprise)

    CLI import (reprise)

    This is a continuation of @int-ua's work in #725, addressing #332. I've resolved conflicts, tweaked the documentation and tests, but otherwise kept it identical.

    I need this feature too, so I'd like to get it merged sooner rather than later. However, there are other tweaks I'd like to make, including:

    • Better documentation, including its own page in the Reference
    • Format options:
      • arg to list available formats, calling into base_formats rather than being hardcoded
      • arg to specify format to use rather than guessing
    • Detect whether supplied class is a Resource or Model rather than needing to specify
    • raise_errors currently defaults to True if dry_run is False - is this the right thing to do?
    • Option to supply kwargs to the Resource constructor (which I need for my own project)
    • Hey, export would be nice too

    ... but let's start with this, and if I get time for those tweaks I'll make them in a separate PR.

    enhancement needs update 
    opened by yozlet 27
  • Added ExportViewMixin

    Added ExportViewMixin

    Created a mixin view to export without admin interface.

    I think it would be a really great thing if we have a generic class based views for this application.

    I tested this patch with a ListView & django_filters.views.FilterView. The 2nd is really useful to replace the AdminFilters

    needs update 
    opened by ZuluPro 23
  • Many to many fields and admin upload

    Many to many fields and admin upload

    Do many to many fields work via admin imports? I keep getting something like this: ValueError('"<Accession: >" needs to have a value for field "accession" before this many-to-many relationship can be used.',)

    It doesn't seem like it can if it's displaying the data to import before importing, as there's no way to get the primary key for the row since it doesn't have one yet?

    Thanks,

    Dean

    opened by lfarrell 23
  • Refactor form-related methods on ImportMixin

    Refactor form-related methods on ImportMixin

    Problem

    Overriding the forms for the import process is currently more difficult than it could be, and there's a bit of 'difficult to follow' stuff going on in the current implementation - particularly in how get_form_kwargs() is used to create the confirmation form.

    Solution

    First of all, new import_form_class and confirm_form_class attributes allow you to easily specify custom form classes for the import process without having to override methods.

    The current get_import_form() and get_import_confirm_form() methods have been deprecated in favour of using the more descriptively named get_import_form_class() and get_confirm_form_class() methods.

    The single get_form_kwargs() method has been deprecated in favour of adding separate methods for each form:

    • get_import_form_kwargs(request, form_class, **kwargs)
    • get_confirm_form_kwargs(request, form_class, import_form=None, **kwargs)

    And to more clearly separate the logic for customising 'intial data' and 'init kwargs', there are separate dedicated methods for each form:

    • get_import_form_initial(request, form_class, **kwargs)
    • get_confirm_form_initial(request, form_class, import_form=None, **kwargs)

    Last but not least, the entire business of form instantiation has been factored out into two new methods:

    • create_import_form(request, **kwargs)
    • create_confirm_form(request, import_form=None, **kwargs)

    These should make it super convenient for modifying forms on the fly.

    Paired with the changes from #1038, this should make for a much more developer-friendly implementation.

    To do

    • [x] Update documentation to reflect changes
    • [x] Write tests to cover new behaviour
    opened by ababic 22
  • datetime field localtime() issue

    datetime field localtime() issue

    Describe the bug Django DateTime Import

    To Reproduce Import DateTime data and you'll hit a "localtime() cannot be applied to a naive datetime", I've been using the package for a while now and use the admin import page as well as a custom import page for users. Both work fine for non-datetime data.

    I've tried this with adding with tz +00 and without 2020-07-17 7:42:39 2020-07-17 7:42:39+00

    I've tried the DateTimeWidget where format="%Y-%m-%d %H:%M:%S" format="%Y-%m-%d %H:%M:%S$z" format=None

    I've posted a SOF question regarding it https://stackoverflow.com/questions/62990575/django-import-export-datetime-naive-datetime-error

    And had a convo specific to it on SOF https://chat.stackoverflow.com/rooms/218260/django-import-export

    The end result seems that the issue may be in the django-import-export package.

    Versions (please complete the following information):

    • django-import-export==2.2.0
    • Python 3.7.4
    • Django==3.0.2

    settings.py

    LANGUAGE_CODE = 'en-us'
    TIME_ZONE = 'UTC'
    USE_I18N = True
    USE_L10N = True
    USE_TZ = True
    

    Expected behavior I was expecting the datetime to import the dates in my csv file

    Screenshots View 2 links above

    Additional context View 2 links above

    bug 
    opened by MrAlexWinkler 21
  • 1.8 compatibility

    1.8 compatibility

      File "/Users/syabro/.envs/homeowners/lib/python2.7/site-packages/import_export/resources.py", line 16, in <module>
        from django.db.models.related import RelatedObject
    ImportError: No module named related
    

    because

    The django.db.models.related module has been removed and the Field.related attribute will be removed in Django 2.0.

    https://docs.djangoproject.com/en/dev/releases/1.8/#model-field-related

    bug 
    opened by syabro 19
  • During import, table id will not be auto-incremented

    During import, table id will not be auto-incremented

    Running on:

    • Django-1.6
    • django-import-export-0.1.5
    • postgresql.x86_64-9.2.5-1
    • tablib-0.9.11
    • python-2.7.5-9

    I have successfully imported data from a csv file.

    When I try to add more data manually, I receive the error:

    duplicate key value violates unique constraint "mytable_pkey"
    DETAIL:  Key (id)=(1) already exists.
    

    From psql:

    select max(id) from mytable;
      75
    
    SELECT nextval('mytable_id_seq');
      2
    

    Does django-import-export support the table's id auto-incrementing?

    opened by raratiru 18
  • Pass row values to every Widget

    Pass row values to every Widget

    AFAIU it will help create widgets with autocreation of related ForeignKey instances that require two fields already present in the row. For example:

    • FK to Person with first_name, last_name
    • FK to Quote that requires a Book (let's suppose it's identifiable just by name) and that book is already in the import fields
    • FK to POI that is identifiable with two (or even three) coordinates
    enhancement 
    opened by int-ua 17
  • added select_ralted option when exporting model resoureces

    added select_ralted option when exporting model resoureces

    Problem

    ovveriding get_queryset not working when exporting from admin panel

    Solution

    How did you solve the problem?

    add export_selected_related option to include when making the queryset

    usage:

    class MyResource(resources.ModelResource):
        export_selected_related = ('RELATED_MODEL1', 'RELATED_MODEL2', ...)
    

    Acceptance Criteria

    Have you written tests? Have you included screenshots of your changes if applicable? Did you document your changes?

    opened by yusufadell 2
  • dry_run kwarg not passed to all methods

    dry_run kwarg not passed to all methods

    dry_run is passed into import_row() but it is hit and miss as to whether this param (and other named kwargs) are passed to subsequent methods such as after_import_instance().

    It would help users (e.g. this example) if these flags were available to other methods. I would propose that they are passed in kwargs rather than as named params, so as not to clutter the method definitions.

    bug enhancement 
    opened by matthewhegarty 0
  • 'list' object is not callable

    'list' object is not callable

    Describe the bug I tried to impliment admin class for Books table along with ImportExportModelAdmin and ImportExportActionModelAdmin. while exporting selected records from admin panel i got the error.

    To Reproduce Steps to reproduce the behavior:

    1. Go to admin.py and impliment custom model admin along with ImportExportModelAdmin and ImportExportActionModelAdmin
    2. Got to respective table in admin panel. Select few records and export them as csv file
    3. See error
    class Base(models.Model):
        slug = models.SlugField(max_length = 200)
    
        class Meta:
            abstract = True
    
    
    class Books(Base):
        name = models.CharField('Book name', max_length=100)
        author = models.ForeignKey(Author, blank=True, null=True)
        author_email = models.EmailField('Author email', max_length=75, blank=True)
        imported = models.BooleanField(default=False)
        published = models.DateField('Published', blank=True, null=True)
        price = models.DecimalField(max_digits=10, decimal_places=2, null=True, blank=True)
        categories = models.ManyToManyField(Category, blank=True)
    
        def __str__(self):
            return self.name
    
    
    class BaseAdmin(admin.ModelAdmin):
        list_display = ('slug', )
    
    
    class BooksResource(ModelResource):
        class Meta:
            model = Books
    
    
    class BooksAdmin(ImportExportModelAdmin, ImportExportActionModelAdmin, BaseAdmin):
        resource_class = [BooksResource]
        list_display = BaseAdmin.list_display + ('name', 'author',  'published', 'price', 'categories', )
    
    
    admin.site.register(Books, BooksAdmin)
    

    Versions (please complete the following information):

    • Django Import Export: [e.g. 3.0.1]
    • Python [e.g. 3.9]
    • Django [e.g. 4.1]

    Expected behavior A clear and concise description of what you expected to happen.

    Screenshots If applicable, add screenshots to help explain your problem.

    Additional context Add any other context about the problem here.

    bug 
    opened by kumar-student 2
  • Rename `after_import_instance()` method for clarity

    Rename `after_import_instance()` method for clarity

    The after_import_instance() is a misnomer because it is called after the instances is loaded (or created) and not after it is imported. Existing clients rely on this method so it would have to be deprecated correctly rather than simply renaming.

    It would also be a good idea to pass the row in as a kwarg so that that users can use row data if they need to.

    enhancement good first time issue 
    opened by matthewhegarty 0
  • handle use case where relations need to be created prior to import

    handle use case where relations need to be created prior to import

    If a user needs to create related objects prior to import and those objects are identified by a combination of fields, then there isn't a 'clean' way of doing this. When the relation is identified by a single field, then we can override ForeignKeyWidget for this, or create data in before_import_row(). The import will skip any fields which are not present in the row, hence using an overridden ForeignKeyWidget won't work, but perhaps using ForeignKeyWidget in some way would be the best solution. It would have to be called if the field was not present in the row data.

    In this related SO issue, I suggest overriding import_obj(), but it would be cleaner to override before_save_instance(). This could be done if the 'row' data is passed to before_save_instance().

    bug 
    opened by matthewhegarty 0
  • `import_obj()` declaration can be improved for consistency

    `import_obj()` declaration can be improved for consistency

    Throughout the code base, the param name row is used to define the incoming row (even though this could be JSON or YAML). In import_obj() it is named data, which is less descriptive. We should standardise variable naming for better readability.

    enhancement good first time issue 
    opened by matthewhegarty 0
Releases(2.8.0)
Rosetta is a Django application that eases the translation process of your Django projects

Rosetta Rosetta is a Django application that facilitates the translation process of your Django projects. Because it doesn't export any models, Rosett

Marco Bonetti 909 Dec 26, 2022
Modular search for Django

Haystack Author: Daniel Lindsley Date: 2013/07/28 Haystack provides modular search for Django. It features a unified, familiar API that allows you to

Haystack Search 3.4k Jan 08, 2023
TinyApp - A Python (Django) Full Stack Application for shortening URLs

TinyApp A Python (Django) Full Stack Application for shortening URLs. How to sta

Li Deng 1 Jan 23, 2022
Full control of form rendering in the templates.

django-floppyforms Full control of form rendering in the templates. Authors: Gregor Müllegger and many many contributors Original creator: Bruno Renié

Jazzband 811 Dec 01, 2022
A CTF leaderboard for the submission of flags during a CTF challenge. Built using Django.

🚩 CTF Leaderboard The goal of this project is to provide a simple web page to allow the participants of an CTF to enter their found flags. Also the l

Maurice Bauer 2 Jan 17, 2022
Django API that scrapes and provides the last news of the city of Carlos Casares by semantic way (RDF format).

"Casares News" API Api that scrapes and provides the last news of the city of Carlos Casares by semantic way (RDF format). Usage Consume the articles

Andrés Milla 6 May 12, 2022
Ugly single sign-on for django projects only

django-usso Ugly single sign-on for django projects only. Do you have many django apps with different users? Do you want to use only one of those apps

Erwin Feser 1 Mar 01, 2022
A django integration for huey task queue that supports multi queue management

django-huey This package is an extension of huey contrib djhuey package that allows users to manage multiple queues. Installation Using pip package ma

GAIA Software 32 Nov 26, 2022
Drf-stripe-subscription - An out-of-box Django REST framework solution for payment and subscription management using Stripe

Drf-stripe-subscription - An out-of-box Django REST framework solution for payment and subscription management using Stripe

Oscar Y Chen 68 Jan 07, 2023
A Django web application that shortens long URLs. This is a demo project to show off my tech abilities.

Django URL Shortener This project is just a complete and production-ready URL shortener web application to show off my tech and coding abilities. Impo

Seyyed Ali Ayati 5 Jan 26, 2022
A Django web application that allows you to be in the loop about everything happening in your neighborhood.

A Django web application that allows you to be in the loop about everything happening in your neighborhood. From contact information of different handyman to meeting announcements or even alerts.

Kennedy Ngugi Mwaura 3 Dec 11, 2022
Domain-driven e-commerce for Django

Domain-driven e-commerce for Django Oscar is an e-commerce framework for Django designed for building domain-driven sites. It is structured such that

Oscar 5.6k Jan 01, 2023
Django Audit is a simple Django app that tracks and logs requests to your application.

django-audit Django Audit is a simple Django app that tracks and logs requests to your application. Quick Start Install django-audit pip install dj-au

Oluwafemi Tairu 6 Dec 01, 2022
AUES Student Management System Developed for laboratory works №9 Purpose using Python (Django).

AUES Student Management System (L M S ) AUES Student Management System Developed for laboratory works №9 Purpose using Python (Django). I've created t

ANAS NABIL 2 Dec 06, 2021
The little ASGI framework that shines. 🌟

✨ The little ASGI framework that shines. ✨ Documentation: https://www.starlette.io/ Community: https://discuss.encode.io/c/starlette Starlette Starlet

Encode 7.7k Dec 31, 2022
This a Django TODO app project and practiced how to deploy and publish the project to Heroku

ToDo App Demo | Project Table of Contents Overview Built With Features How to use Acknowledgements Contact Overview Built With HTML CSS JS Django How

Cetin OGUT 1 Nov 19, 2021
A real-time photo feed using Django and Pusher

BUILD A PHOTO FEED USING DJANGO Here, we will learn about building a photo feed using Django. This is similar to instagram, but a stripped off version

samuel ogundipe 4 Jan 01, 2020
DRF_commands is a Django package that helps you to create django rest framework endpoints faster using manage.py.

DRF_commands is a Django package that helps you to create django rest framework endpoints faster using manage.py.

Mokrani Yacine 2 Sep 28, 2022
Djangoblog - A blogging platform built on Django and Python.

djangoblog 👨‍💻 A blogging platform built on Django and Python

Lewis Gentle 1 Jan 10, 2022
Source files for a free pyRevit toolbar.

pyRoovit (WIP) What is this? PyRoovit is/will be a toolbar for the use with pyRevit built by Gavin Crump (aka Aussie BIM Guru). Having used and taught

Gavin Crump 11 Nov 10, 2022