Simple csv to model parsing for Django.
Project description
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 hashes)