Skip to content

Instantly share code, notes, and snippets.

@rcotrina94
Last active March 24, 2016 17:30
Show Gist options
  • Save rcotrina94/df3b6db2332c2229086c to your computer and use it in GitHub Desktop.
Save rcotrina94/df3b6db2332c2229086c to your computer and use it in GitHub Desktop.
Exportar en Django con "django-export-import"

Exportar en Django con "django-export-import"

django-export-import es un paquete de django que nos facilita la tarea de exportar e importar desde y hacia diferentes formatos de datos (CSV, XLS, JSON, HTML).

Éste paquete tiene 4 clases que serán las que más se utilizarían para exportar (y quizás también importar) fácilmente desde nuestra aplicación de Django.

class import_export.resource.ModelResource

Ésta clase nos sirve para poder utilizar los modelos de Django como recursos (Resources)

class import_export.resource.ResourceOptions (Meta)

La clase Meta nos permite configurar cómo se comportará el Resource. Están disponibles las siguiente opciones:

exclude = None

Una lista negra de campos (fields). Controla qué campos del Resource no deben aparecer.

export_order = None

Controls export order for columns.

fields = None

Controls what introspected fields the Resource should include. A whitelist of fields.

import_id_fields = [u'id']

Controls which object fields will be used to identify existing instances.

instance_loader_class = None

Controls which class instance will take care of loading existing objects.

model = None

Django Model class. It is used to introspect available fields.

report_skipped = True

Controls if the result reports skipped rows Default value is True

skip_unchanged = False

Controls if the import should skip unchanged records. Default value is False

use_transactions = None

Controls if import should use database transactions. Default value is None meaning settings.IMPORT_EXPORT_USE_TRANSACTIONS will be evaluated.

widgets = None

This dictionary defines widget kwargs for fields.

class import_export.admin.*

class import_export.admin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment