Prometheus
Prometheus

Reputation: 33625

Importing a CSV using celery

I want to allow my users to upload a CSV of contact data that will populate a a model called contacts. I have used django-csv-importer and this seems to work ok. However, I would like to use maybe something like celery so that users can upload and just forget about waiting ( at the moment it can take 5 minutes).

Are they any projects that do what django-csv-importer does but with celery integration part? If so could someone give me any example if there is a better way?

Many thanks.

Upvotes: 0

Views: 1997

Answers (2)

Andrew Ingram
Andrew Ingram

Reputation: 5220

Happily I've worked with the author of django-csv-importer, and can report there's a newer version in the form of django-adaptors (https://github.com/anthony-tresontani/django-adaptors), it's the same project but renamed, so it might have some new stuff.

As for your specific question, joshua's answer is correct. But if you want a ridiculously rich implementation complete with audit trails, take a look at this: http://codeinthehole.com/writing/use-models-for-uploads/

Upvotes: 2

joshua
joshua

Reputation: 2519

in tasks.py

from celery.task import task

@task
def import_csv(filename):
    my_csv_list = MyCsvModel.import_data(data = open(filename))
    ...

Then just call import_csv.delay(filename) in your view.

Upvotes: 1

Related Questions