{"id":15295813,"url":"https://github.com/narenchoudhary/django-export-csv","last_synced_at":"2025-04-13T18:23:00.951Z","repository":{"id":57419608,"uuid":"74449705","full_name":"narenchoudhary/django-export-csv","owner":"narenchoudhary","description":"A small django application which provides generic views for downloading csv (This project isn't ready for production use yet)","archived":false,"fork":false,"pushed_at":"2017-07-21T16:16:34.000Z","size":45,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-27T09:11:26.472Z","etag":null,"topics":["csv","django","django-application","exporter"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/narenchoudhary.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-11-22T08:13:59.000Z","updated_at":"2022-01-20T10:21:50.000Z","dependencies_parsed_at":"2022-09-13T07:21:22.902Z","dependency_job_id":null,"html_url":"https://github.com/narenchoudhary/django-export-csv","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/narenchoudhary%2Fdjango-export-csv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/narenchoudhary%2Fdjango-export-csv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/narenchoudhary%2Fdjango-export-csv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/narenchoudhary%2Fdjango-export-csv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/narenchoudhary","download_url":"https://codeload.github.com/narenchoudhary/django-export-csv/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248305879,"owners_count":21081562,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csv","django","django-application","exporter"],"created_at":"2024-09-30T18:08:16.546Z","updated_at":"2025-04-13T18:23:00.924Z","avatar_url":"https://github.com/narenchoudhary.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"django-export-csv\n=================\n\n.. image:: https://travis-ci.org/narenchoudhary/django-export-csv.svg?branch=master\n    :target: https://travis-ci.org/narenchoudhary/django-export-csv\n    :alt: CI status\n\n.. image:: https://codecov.io/gh/narenchoudhary/django-export-csv/branch/master/graph/badge.svg\n    :target: https://codecov.io/gh/narenchoudhary/django-export-csv\n    :alt: Coverage Status\n\n.. image:: https://requires.io/github/narenchoudhary/django-export-csv/requirements.svg?branch=master\n     :target: https://requires.io/github/narenchoudhary/django-export-csv/requirements/?branch=master\n     :alt: Requirements Status\n\n.. image:: https://img.shields.io/badge/License-BSD%203--Clause-blue.svg\n    :target: https://opensource.org/licenses/BSD-3-Clause\n    :alt: License Status\n\n``django-export-csv`` is a reusable Django application for which provides generic views for downloading CSV files.\n\n\nInstallation\n============\n\nTo get started using ``django-export-csv`` simply install it with\n\n.. code-block:: python\n\n    pip install django-csv-export\n\n\nUsage\n=====\n\nAdd ``'export_csv'`` to INSTALLED_APPS settings of the project.\n\n.. code-block:: python\n\n    INSTALLED_APPS = [\n        'django.contrib.admin',\n        'django.contrib.auth',\n        ...\n        ...\n        'export_csv',\n    ]\n\n\n\nSubclass ``ExportCSV`` in views.py file and provide model attribute.\n\n\n.. code-block:: python\n\n    from export_csv.views import ExportCSV\n\n    from .models import Account\n\n    class AccountCSV(ExportCSV):\n        \"\"\"View for creating and rendering CSV of all Account model instances.\"\"\"\n        model = Customer\n\n\n\nIn urls.py, add url pointing to the view class ``AccountCSV`` declared above.\n\n.. code-block:: python\n\n    from .views import AccountCSV\n\n    urlpatterns = [\n        (r'^account_csv/$', AccountCSV.as_view(), name='account-csv'),\n    ]\n\n\nThat's it. It will render a CSV file containing all the fields of all the instances of ``Account`` model.\n\nCustomizing ExportCSV View\n==========================\n\n.. note::\n    All examples follow from the models in the example project.\n\nUse custom queryset\n-------------------\n\nBy default, all instances of the ``model`` are included in (the queryset and)\nthe CSV.\n\nTo provide a custom queryset, override ``get_queryset`` method to return\ncustom queryset.\n\n.. code-block:: python\n\n    class AccountCSV(ExportCSV):\n        model = Account\n\n        def get_queryset(self):\n            return Account.object.filter(is_active=True)\n\n\nOnly include certain fields of the model\n----------------------------------------\n\nIt is possible that only some fields of the ``model`` are needed.\n\nThis can be achieved in two ways:\n\n- provide ``field_names`` list\n\n- override ``get_field_names`` method\n\n.. code-block:: python\n\n    class AccountCSV(ExportCSV):\n        model = Account\n        field_names = ['owner', 'account_no', 'balance']\n\n\n.. code-block:: python\n\n    class AccountCSV(ExportCSV):\n        model = Account\n\n        def get_field_names(self):\n            return ['owner', 'account_no', 'balance']\n\nProvide filename\n----------------\n\nBy default, the CSV rendered will have filename *\u003cmodel\u003e_list.csv*. For\nexample, for ``Account`` model the filename will be *account_list.csv*.\n\nCustom file name can be provided using two ways.\n\n- provide ``filename`` attribute\n- Override ``get_filename`` method.\n\n.. code-block:: python\n\n    class AccountCSV(ExportCSV):\n        model = Account\n        filename = 'active_account_list.csv'\n\n        def get_queryset(self):\n            return Account.object.filter(is_active=True)\n\n\n.. code-block:: python\n\n    class AccountCSV(ExportCSV):\n        model = Account\n\n        def get_queryset(self):\n            return Account.object.filter(is_active=True)\n\n        def get_filename(self):\n            return 'active_account_list.csv'\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnarenchoudhary%2Fdjango-export-csv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnarenchoudhary%2Fdjango-export-csv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnarenchoudhary%2Fdjango-export-csv/lists"}