Skip to main content

Simple csv to model parsing for Django.

Project description

Build Status

Django-CSVExport

This is a django extension that simplifies model to csv conversions.

Requirements

  • Python 2.7

  • Django 1.6+

Example:

Simple usage:

from csvexport.exports import ModelCSVExporter

records = Record.objects.all()
exp = ModelExporter(queryset=records)
f = exp.to_string()

With specified fields

from csvexport.exports import ModelCSVExporter

class RecordExporter(ModelCSVExporter):
    class Meta:
        fields = ["album", "slug"]
        exclude = ["id"]


records = Record.objects.all()
exp = RecordExporter(queryset=records)
f = exp.to_string()

With custom hydration:

class RecordExporter(ModelExporter):
    class Meta:
        fields = ["artist", "title", "release_year", "format", "quality",
                  "record_label", "comment", "venue", "url"]

    def hydrate_entry(self, entry):
        venue_name = ""

        if entry.venue:
            venue_name = entry.venue.name

        return {
            "artist": entry.album.artist.name,
            "title": entry.album.name,
            "release_year": entry.album.release_year,
            "format": entry.format,
            "quality": entry.quality,
            "record_label": entry.record_label,
            "comment": entry.comment,
            "venue": venue_name,
        }


records = Record.objects.all()
exp = RecordExporter(queryset=records)
f = exp.to_string()

Contributing

Want to contribute? Awesome. Just send a pull request.

License

Django-CSVExport is released under the MIT License.

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

django-csvexport-1.0.3.tar.gz (6.0 kB view details)

Uploaded Source

File details

Details for the file django-csvexport-1.0.3.tar.gz.

File metadata

File hashes

Hashes for django-csvexport-1.0.3.tar.gz
Algorithm Hash digest
SHA256 3df98fcf93295c3d8bc9d9526ac2d1dd9a371b3beb997eb403b0cd0108b419c6
MD5 898129308e6bb1e1265539b7ad2cbc63
BLAKE2b-256 90a66cef61bd46942559e2be52a8be6a90d3928afd71fc69238dcde519374ca1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page