Skip to main content

Simple csv to model parsing for Django.

Project description

Simple csv to model parsing for Django.

---

# Django-CSVExport

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


## Requirements
- Python 2.7
- Django 1.7+


## Example:

### Simple usage:

```python
from csvexport.exports import ModelCSVExporter

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

### With specified fields

```python
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:

```python
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](http://www.opensource.org/licenses/MIT).

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.0.tar.gz (4.5 kB view details)

Uploaded Source

File details

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

File metadata

File hashes

Hashes for django-csvexport-1.0.0.tar.gz
Algorithm Hash digest
SHA256 59eb8d50b3c971026c71e700cfed8189d074c0b329519d960bace45f174d101f
MD5 c21f10d7c5b8a9051b83a2820f93315d
BLAKE2b-256 658f108c9887ac749c1d53b4c72164683daaec1c115ed05c89badcfd273c6406

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