Export asynchronously your data from your Django models
Project description
django-data-exporter is a simple Django application to export asynchronously your data from your models.
It’s based on Celery (>= 2.3) to use Chords and tablib to export your data in multiple formats.
Installation
Utilisation
django-data-exporter uses channels to discover your exports and to transfer them to celery. So let’s say you have the following model in a polls application
# polls/models.py from django.db import models class Poll(models.Model): question = models.CharField(max_length=200) pub_date = models.DateTimeField('date published') def __unicode__(self): return self.question
Now, you want to define your first exporter right? Create a exports.py file in your polls application and extend Export to build your own Exporter
# polls/exports.py from data_exporter.base import Export from polls.models import Poll class PollExport(Export): filename = 'poll' columns = ('id', 'question') headers = ('id', 'question') directory = 'polls' def get_query(self, offset=None, limit=None): qs = Poll.objects.all() if offset and limit: return qs[offset:limit] if limit: return qs[:limit] if offset: return qs[offset:] return qs def get_count(self): return Poll.objects.count()
Final step is to register this exporter in DATA_EXPORTER_CHANNELS in your Django settings
DATA_EXPORTER_CHANNELS = { 'polls': 'polls.exports.PollExport' }
You can now use the celery tasks provided by django-data-exporter as so
from data_exporter.tasks import builder builder.delay('polls', 'csv')
First parameter is the name of your channel and second parameter is the format wanted.
As said before, we use the beautiful tablib library to export your data, so as you may understood we support all formats provided by this library.
Configuration
DATA_EXPORTER_CHANNELS
All your registered channels.
DATA_EXPORTER_DIRECTORY
The directory used to export your data.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for django-data-exporter-0.1.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0a8bf965d217a9f3f7731c3612141792f962a6d0a5317d18b735d368c8c3c7c |
|
MD5 | 1daadfe8b0ef467e56150ef81d7f032d |
|
BLAKE2b-256 | f065031e0711c3630762e9517e881aef12b613e5b60ab8892bc3a3c17ae87205 |