{"id":959,"date":"2021-01-25T21:45:29","date_gmt":"2021-01-25T18:45:29","guid":{"rendered":"https:\/\/www.etemkeskin.com\/?p=959"},"modified":"2021-01-25T22:50:16","modified_gmt":"2021-01-25T19:50:16","slug":"django-uygulamalarinda-excel-csv-json-gibi-farkli-formattaki-veriyi-ice-ve-disa-aktarma","status":"publish","type":"post","link":"https:\/\/www.etemkeskin.com\/index.php\/tr\/2021\/01\/25\/django-uygulamalarinda-excel-csv-json-gibi-farkli-formattaki-veriyi-ice-ve-disa-aktarma\/","title":{"rendered":"Django Uygulamalar\u0131nda Excel, CSV, JSON gibi Farkl\u0131 Formattaki Veriyi \u0130\u00e7e ve D\u0131\u015fa Aktarma"},"content":{"rendered":"\n<p>Django ile web uygulamalar\u0131 geli\u015ftirdi\u011fimizde veri taban\u0131na farkl\u0131 formatlarda verilerimizi aktarmak veya veritaban\u0131ndaki verileri tablo halinde elde etmek isteriz. <strong>django-import-export<\/strong> paketi bizim i\u00e7in bu i\u015flemi kolayla\u015ft\u0131ran bir pakettir. Paket Excel, CSV, JSON gibi farkl\u0131 formattaki verileri desteklemektedir.<\/p>\n\n\n\n<h4>Kurulum<\/h4>\n\n\n\n<p>Paket kurulumu i\u00e7in <strong>pip<\/strong> paket y\u00f6neticisini kullanarak paketi bilgisayar\u0131m\u0131za y\u00fckl\u00fcyoruz.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;htmlmixed&quot;,&quot;mime&quot;:&quot;text\/html&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;showPanel&quot;:false,&quot;language&quot;:&quot;HTML&quot;,&quot;modeName&quot;:&quot;html&quot;}\">pip install django-import-export<\/pre><\/div>\n\n\n\n<p>Daha sonra <strong>settings.py<\/strong> dosyam\u0131za a\u015fa\u011f\u0131daki kodlar\u0131 ekleyerek uygulamam\u0131za tan\u0131ml\u0131yoruz. Ayr\u0131ca veriyi i\u00e7e(import) veya d\u0131\u015fa(export) aktarma yaparken bir problem \u00e7\u0131karsa veri b\u00fct\u00fcnl\u00fc\u011f\u00fcn\u00fc sa\u011flamak i\u00e7in <code>IMPORT_EXPORT_USE_TRANSACTIONS = True<\/code> olarak tan\u0131ml\u0131yoruz.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;showPanel&quot;:false,&quot;language&quot;:&quot;Python&quot;,&quot;modeName&quot;:&quot;python&quot;}\">INSTALLED_APPS = (\n    ...\n    'import_export',\n)\n# The default value is False\nIMPORT_EXPORT_USE_TRANSACTIONS = True<\/pre><\/div>\n\n\n\n<p><strong>django-import-export<\/strong> paketini kullan\u0131rken paketin nas\u0131l \u00e7al\u0131\u015faca\u011f\u0131n\u0131 tan\u0131mlad\u0131\u011f\u0131m\u0131z  model s\u0131n\u0131flar\u0131m\u0131za benzeyen <strong>Resource<\/strong> konsepti bulunmaktad\u0131r. Bunun i\u00e7in uygulamam\u0131z\u0131n i\u00e7inde <strong>resource.py<\/strong> isminde dosya olu\u015fturuyoruz.<\/p>\n\n\n\n<p>models.py dosyam\u0131zda Category ve Comment ad\u0131nda iki model tan\u0131mlad\u0131k. Comment&#8217; leri <strong>django-import-export<\/strong> paketi ile i\u00e7e ve d\u0131\u015fa aktaraca\u011f\u0131z.<\/p>\n\n\n\n<h5>models.py<\/h5>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;showPanel&quot;:false,&quot;language&quot;:&quot;Python&quot;,&quot;modeName&quot;:&quot;python&quot;}\">from django.db import models\n\nclass Category(models.Model):\n    title = models.CharField(max_length = 500, unique=True) \n\n    def __str__(self):\n        return &quot;{0}&quot;.format(self.title)\n\nclass Comment(models.Model):\n    description = models.TextField()\n    category = models.ForeignKey(Category, on_delete= models.CASCADE )<\/pre><\/div>\n\n\n\n<p><strong>resources.py<\/strong> dosyas\u0131nda hangi model kullan\u0131laca\u011f\u0131n\u0131 tan\u0131ml\u0131yoruz.<\/p>\n\n\n\n<p><strong>resources.py<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;showPanel&quot;:false,&quot;language&quot;:&quot;Python&quot;,&quot;modeName&quot;:&quot;python&quot;}\">from import_export import resources\nfrom label.models import Comment\n\nclass CommentResource(resources.ModelResource):\n    class Meta:\n        model = Comment<\/pre><\/div>\n\n\n\n<p>Dosya yap\u0131s\u0131 a\u015fa\u011f\u0131daki resimdeki gibidir:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"128\" height=\"241\" src=\"https:\/\/www.etemkeskin.com\/wp-content\/uploads\/2021\/01\/image-5.png\" alt=\"\" class=\"wp-image-969\"\/><\/figure>\n\n\n\n<h4>Veriyi D\u0131\u015fa Aktarma<\/h4>\n\n\n\n<p>Veritaban\u0131m\u0131zdaki Comment tablosunu frontendde bir form olu\u015fturarak kullan\u0131c\u0131n\u0131n istedi\u011fi formatta bilgisayar\u0131na indirebilmesini sa\u011flayaca\u011f\u0131z. Bunu i\u00e7in ilk \u00f6nce <strong>urls.py<\/strong> path&#8217; imizi tan\u0131mlayaca\u011f\u0131z.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;showPanel&quot;:false,&quot;language&quot;:&quot;Python&quot;,&quot;modeName&quot;:&quot;python&quot;}\">path('export-data\/', export_data, name=&quot;export_data&quot;),<\/pre><\/div>\n\n\n\n<p>Daha sonra <strong>export_data.html <\/strong>isminde template i olu\u015fturuyoruz. Bu template &#8216; te formumuzu olu\u015ftural\u0131m.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;htmlmixed&quot;,&quot;mime&quot;:&quot;text\/html&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;HTML&quot;,&quot;modeName&quot;:&quot;html&quot;}\">{% block content %}\n&lt;div class=&quot;card card-secondary&quot;&gt;\n  &lt;div class=&quot;card-header&quot;&gt;\n    &lt;h3 class=&quot;card-title&quot;&gt;Export Comments&lt;\/h3&gt;\n  &lt;\/div&gt;\n  &lt;div class=&quot;card-body&quot;&gt;\n    &lt;form role=&quot;form&quot; method=&quot;POST&quot; action=&quot;{% url 'label:export_data' %}&quot; enctype=&quot;multipart\/form-data&quot;&gt;\n      {% csrf_token %}\n        &lt;div class=&quot;form-group&quot;&gt;\n          &lt;label&gt;Choose Format Type&lt;\/label&gt;\n          &lt;select class=&quot;custom-select&quot; name=&quot;file-format&quot;&gt;\n            &lt;option selected&gt;Choose format...&lt;\/option&gt;\n            &lt;option&gt;CSV&lt;\/option&gt;\n            &lt;option&gt;JSON&lt;\/option&gt;\n            &lt;option&gt;XLS (Excel)&lt;\/option&gt;\n          &lt;\/select&gt;\n        &lt;\/div&gt; &lt;br&gt;&lt;br&gt;&lt;br&gt;\n      &lt;button type=&quot;submit&quot; class=&quot;btn btn-info btn-block&quot;&gt;Export&lt;\/button&gt;\n    &lt;\/form&gt;\n  &lt;\/div&gt;\n&lt;\/div&gt;\n{% endblock %} <\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"764\" height=\"488\" src=\"https:\/\/www.etemkeskin.com\/wp-content\/uploads\/2021\/01\/image-6.png\" alt=\"\" class=\"wp-image-978\"\/><\/figure>\n\n\n\n<p><strong>views.py<\/strong><\/p>\n\n\n\n<p>views.py dosyas\u0131nda form post edildi\u011finde \u00e7al\u0131\u015facak fonksiyonu tan\u0131mlad\u0131k.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;Python&quot;,&quot;modeName&quot;:&quot;python&quot;}\">from django.http import HttpResponse\nfrom .resources import CommentResource\ndef export_data(request):\n    if request.method == 'POST':\n        # Get selected option from form\n        file_format = request.POST['file-format']\n        comment_resource = CommentResource()\n        dataset = comment_resource.export()\n        if file_format == 'CSV':\n            response = HttpResponse(dataset.csv, content_type='text\/csv')\n            response['Content-Disposition'] = 'attachment; filename=&quot;exported_data.csv&quot;'\n            return response        \n        elif file_format == 'JSON':\n            response = HttpResponse(dataset.json, content_type='application\/json')\n            response['Content-Disposition'] = 'attachment; filename=&quot;exported_data.json&quot;'\n            return response\n        elif file_format == 'XLS (Excel)':\n            response = HttpResponse(dataset.xls, content_type='application\/vnd.ms-excel')\n            response['Content-Disposition'] = 'attachment; filename=&quot;exported_data.xls&quot;'\n            return response   \n    return render(request, 'label\/export_import_data_page.html') <\/pre><\/div>\n\n\n\n<h4>Veriyi \u0130\u00e7e Aktarma<\/h4>\n\n\n\n<p>Frontend&#8217; de form olu\u015fturarak kullan\u0131c\u0131n\u0131n CSV veya JSON  format\u0131ndaki verisini veritaban\u0131na y\u00fckleyece\u011fiz. \u0130lk \u00f6nce form post edildi\u011finde \u00e7al\u0131\u015facak path&#8217; i tan\u0131ml\u0131yoruz. <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;showPanel&quot;:false,&quot;language&quot;:&quot;Python&quot;,&quot;modeName&quot;:&quot;python&quot;}\">path('import-data\/', import_data, name=&quot;import_data&quot;),<\/pre><\/div>\n\n\n\n<p>A\u015fa\u011f\u0131da templatimizde kullan\u0131lacak formun kodu bulunmaktad\u0131r.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;htmlmixed&quot;,&quot;mime&quot;:&quot;text\/html&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;HTML&quot;,&quot;modeName&quot;:&quot;html&quot;}\">{% block content %}\n&lt;div class=&quot;card card-secondary&quot;&gt;\n  &lt;div class=&quot;card-header&quot;&gt;\n    &lt;h3 class=&quot;card-title&quot;&gt;Import Comments&lt;\/h3&gt;\n  &lt;\/div&gt;\n  &lt;div class=&quot;card-body&quot;&gt;\n    &lt;form role=&quot;form&quot; method=&quot;POST&quot; action=&quot;{% url 'label:import_data' %}&quot; enctype=&quot;multipart\/form-data&quot;&gt;\n      {% csrf_token %}\n      &lt;div class=&quot;form-group&quot;&gt;\n        &lt;label&gt;Choose Format Type&lt;\/label&gt;&lt;br&gt;           \n        &lt;input class=&quot;mb-2&quot; type=&quot;file&quot; name=&quot;importData&quot;&gt;\n        &lt;select class=&quot;custom-select&quot; name=&quot;file-format1&quot;&gt; \n          &lt;option selected&gt;Choose format...&lt;\/option&gt;\n          &lt;option&gt;CSV&lt;\/option&gt;\n          &lt;option&gt;JSON&lt;\/option&gt;\n        &lt;\/select&gt;\n      &lt;\/div&gt; &lt;br&gt;&lt;br&gt;&lt;br&gt;\n      &lt;button type=&quot;submit&quot; class=&quot;btn btn-info btn-block&quot;&gt;Import&lt;\/button&gt;\n    &lt;\/form&gt;\n  &lt;\/div&gt;\n&lt;\/div&gt;\n{% endblock %} <\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"469\" height=\"343\" src=\"https:\/\/www.etemkeskin.com\/wp-content\/uploads\/2021\/01\/image-10.png\" alt=\"\" class=\"wp-image-988\"\/><\/figure>\n\n\n\n<p><strong>views.py<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;Python&quot;,&quot;modeName&quot;:&quot;python&quot;}\">from tablib import Dataset\ndef import_data(request):\n    if request.method == 'POST':\n        file_format = request.POST['file-format1']\n        comment_resource = CommentResource()\n        dataset = Dataset()\n        new_comments = request.FILES['importData']\n\n        if file_format == 'CSV':\n            imported_data = dataset.load(new_comments.read().decode('utf-8'),format='csv')\n            result = comment_resource.import_data(dataset, dry_run=True)                                                                 \n        elif file_format == 'JSON':\n            imported_data = dataset.load(new_comments.read().decode('utf-8'),format='json')\n            # Testing data import\n            result = comment_resource.import_data(dataset, dry_run=True) \n\n        if not result.has_errors():\n            # Import now\n            comment_resource.import_data(dataset, dry_run=False)\n\n    return render(request, 'label\/export_import_data_page.html')')<\/pre><\/div>\n\n\n\n<p>Category modelini Comment modelimize bire \u00e7ok ili\u015fkisi bulunmaktad\u0131r. Bu ili\u015fkiyide y\u00f6netebilmemiz i\u00e7in resource.py dosyam\u0131z\u0131 de\u011fi\u015ftimemiz gerekiyor.  <\/p>\n\n\n\n<p><strong>resources.py<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;Python&quot;,&quot;modeName&quot;:&quot;python&quot;}\">from import_export import resources, widgets, fields\nfrom label.models import Comment, Category\n\nclass CharRequiredWidget(widgets.CharWidget):\n    def clean(self, value, row=None, *args, **kwargs):\n        val = super().clean(value)\n        if val:\n            return val\n        else:\n            raise ValueError('this field is required')\n\nclass ForeignkeyRequiredWidget(widgets.ForeignKeyWidget):\n    def clean(self, value, row=None, *args, **kwargs):\n        if value:\n            print(self.field, value)\n            return self.get_queryset(value, row, *args, **kwargs).get(**{self.field: value})\n        else:\n            raise ValueError(self.field+ &quot; required&quot;)\n\nclass CommentResource(resources.ModelResource):\n    category = fields.Field(column_name='category', attribute='category', widget=ForeignkeyRequiredWidget(Category, 'title'),\n                        saves_null_values=False) # title Category modelindeki kolon ismi\n    description = fields.Field(saves_null_values=False, column_name='description', attribute='description',\n                          widget=CharRequiredWidget())\n\n    class Meta:\n        model = Comment\n        fields = ('id', 'description', 'category')\n        clean_model_instances = True\n\n# class CommentResource(resources.ModelResource):\n#     class Meta:\n#         model = Comment<\/pre><\/div>\n\n\n\n<p>A\u015fa\u011f\u0131daki CSV dosya yap\u0131s\u0131 ile uygulamam\u0131z\u0131 deneyebiliriz.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;showPanel&quot;:false,&quot;language&quot;:&quot;C&quot;,&quot;modeName&quot;:&quot;c&quot;}\">id,category,description\n1,Computer,Lorem ipsum dolor sit amet, consectetur \n2,Computer,adipiscing elit, sed do eiusmod tempor incididunt ut \n3,TV,labore et dolore magna aliqua. Ut enim ad minim veniam, quis nost  \n4,TV,Sed ut perspiciatis unde omnis iste natus error sit voluptatem \n5,TV,accusantium doloremque laudantium, totam rem aperiam, eaque ipsa<\/pre><\/div>\n\n\n\n<h4>Django Admin Paneli<\/h4>\n\n\n\n<p><strong>admin.py<\/strong> dosyas\u0131na a\u015fa\u011f\u0131daki kodlar\u0131 ekleyerek Django Admin panelinde comment modelimiz i\u00e7in i\u00e7e ve d\u0131\u015fa aktarma i\u015flemlerini kolayca yapabiliriz.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;showPanel&quot;:false,&quot;language&quot;:&quot;Python&quot;,&quot;modeName&quot;:&quot;python&quot;}\">from django.contrib import admin\nfrom label.models import  Comment\nfrom import_export.admin import ImportExportModelAdmin\n\n@admin.register(Comment)\nclass CommentAdmin(ImportExportModelAdmin):\n    pass\n<\/pre><\/div>\n\n\n\n<p>Yukar\u0131daki kodlar\u0131 ekledi\u011fimizde Admin panelinde Comment modeline girdi\u011fimizde sa\u011f \u00fcstte IMPORT ve EXPORT ad\u0131nda iki d\u00fc\u011fmenin belirdi\u011fini g\u00f6receksiniz. EXPORT d\u00fc\u011fmesine basarak a\u015fa\u011f\u0131daki resimde de g\u00f6r\u00fcld\u00fc\u011f\u00fc gibi bir \u00e7ok formatta Comment tablomuzu d\u0131\u015fa aktarabiliriz.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1066\" height=\"311\" src=\"https:\/\/www.etemkeskin.com\/wp-content\/uploads\/2021\/01\/image-7.png\" alt=\"\" class=\"wp-image-982\"\/><\/figure>\n\n\n\n<p>Export dedi\u011fimizde \u00e7\u0131kacak ekranda hangi formatta olmas\u0131n\u0131 tan\u0131mlayaca\u011f\u0131m\u0131z form kar\u015f\u0131m\u0131za \u00e7\u0131kacakt\u0131r.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"711\" height=\"440\" src=\"https:\/\/www.etemkeskin.com\/wp-content\/uploads\/2021\/01\/image-8.png\" alt=\"\" class=\"wp-image-984\"\/><\/figure>\n\n\n\n<p>E\u011fer Admin panelinde Export ve Import formlar\u0131n\u0131 customize etmek istiyorsak <strong>admin.py<\/strong> deki dosyam\u0131z\u0131 a\u015fa\u011f\u0131daki \u015fekilde d\u00fczenleyebiliriz.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;Python&quot;,&quot;modeName&quot;:&quot;python&quot;}\">from django.contrib import admin\nfrom label.models import  Comment, Category\nfrom import_export.admin import ImportExportModelAdmin\n# 1 METHOD\n# @admin.register(Comment)\n# class CommentAdmin(ImportExportModelAdmin):\n#     pass\n\n# 2 METHOD\nfrom .resources import CommentResource\nclass CommentAdmin(ImportExportModelAdmin):\n    resource_class = CommentResource\n    list_display = ('description', 'category')\n\nadmin.site.register(Comment, CommentAdmin)<\/pre><\/div>\n\n\n\n<p>Django projelerinde kullanabilece\u011finiz \u00e7ok kullan\u0131\u015fl\u0131 bir pakettir. Bu yaz\u0131da kullan\u0131labilecek t\u00fcm durumlar\u0131 basit ve a\u00e7\u0131k bir \u015fekilde anlatmaya \u00e7al\u0131\u015ft\u0131m. Ba\u015far\u0131lar.<\/p>\n\n\n\n<h6>Kaynaklar <\/h6>\n\n\n\n<ol><li>https:\/\/django-import-export.readthedocs.io\/en\/latest\/index.html<\/li><\/ol>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Django ile web uygulamalar\u0131 geli\u015ftirdi\u011fimizde veri taban\u0131na farkl\u0131 formatlarda verilerimizi aktarmak veya veritaban\u0131ndaki verileri tablo halinde elde etmek isteriz. django-import-export paketi bizim i\u00e7in bu i\u015flemi kolayla\u015ft\u0131ran bir pakettir. Paket Excel, CSV, JSON gibi farkl\u0131 formattaki verileri desteklemektedir. Kurulum Paket kurulumu i\u00e7in pip paket y\u00f6neticisini kullanarak paketi bilgisayar\u0131m\u0131za y\u00fckl\u00fcyoruz. Daha sonra settings.py dosyam\u0131za a\u015fa\u011f\u0131daki kodlar\u0131 ekleyerek [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[32,26],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v16.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Django Uygulamalar\u0131nda Excel, CSV, JSON gibi Farkl\u0131 Formattaki Veriyi \u0130\u00e7e ve D\u0131\u015fa Aktarma - blog website<\/title>\n<meta name=\"description\" content=\"Django ile web uygulamalar\u0131 geli\u015ftirdi\u011fimizde veri taban\u0131na farkl\u0131 formatlarda verilerimizi aktarmak veya veritaban\u0131ndaki verileri tablo halinde elde etmek isteriz. django-import-export paketi bizim i\u00e7in bu i\u015flemi kolayla\u015ft\u0131ran bir pakettir. Paket Excel, CSV, JSON gibi farkl\u0131 formattaki verileri desteklemektedir.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.etemkeskin.com\/index.php\/tr\/2021\/01\/25\/django-uygulamalarinda-excel-csv-json-gibi-farkli-formattaki-veriyi-ice-ve-disa-aktarma\/\" \/>\n<meta property=\"og:locale\" content=\"tr_TR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Django Uygulamalar\u0131nda Excel, CSV, JSON gibi Farkl\u0131 Formattaki Veriyi \u0130\u00e7e ve D\u0131\u015fa Aktarma - blog website\" \/>\n<meta property=\"og:description\" content=\"Django ile web uygulamalar\u0131 geli\u015ftirdi\u011fimizde veri taban\u0131na farkl\u0131 formatlarda verilerimizi aktarmak veya veritaban\u0131ndaki verileri tablo halinde elde etmek isteriz. django-import-export paketi bizim i\u00e7in bu i\u015flemi kolayla\u015ft\u0131ran bir pakettir. Paket Excel, CSV, JSON gibi farkl\u0131 formattaki verileri desteklemektedir.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.etemkeskin.com\/index.php\/tr\/2021\/01\/25\/django-uygulamalarinda-excel-csv-json-gibi-farkli-formattaki-veriyi-ice-ve-disa-aktarma\/\" \/>\n<meta property=\"og:site_name\" content=\"blog website\" \/>\n<meta property=\"article:published_time\" content=\"2021-01-25T18:45:29+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-01-25T19:50:16+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.etemkeskin.com\/wp-content\/uploads\/2021\/01\/image-5.png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Tahmini okuma s\u00fcresi\" \/>\n\t<meta name=\"twitter:data1\" content=\"7 dakika\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.etemkeskin.com\/#website\",\"url\":\"https:\/\/www.etemkeskin.com\/\",\"name\":\"blog website\",\"description\":\"Etem KESK\\u0130N\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/www.etemkeskin.com\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"tr\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.etemkeskin.com\/index.php\/tr\/2021\/01\/25\/django-uygulamalarinda-excel-csv-json-gibi-farkli-formattaki-veriyi-ice-ve-disa-aktarma\/#primaryimage\",\"inLanguage\":\"tr\",\"url\":\"https:\/\/www.etemkeskin.com\/wp-content\/uploads\/2021\/01\/image-5.png\",\"contentUrl\":\"https:\/\/www.etemkeskin.com\/wp-content\/uploads\/2021\/01\/image-5.png\",\"width\":128,\"height\":241},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.etemkeskin.com\/index.php\/tr\/2021\/01\/25\/django-uygulamalarinda-excel-csv-json-gibi-farkli-formattaki-veriyi-ice-ve-disa-aktarma\/#webpage\",\"url\":\"https:\/\/www.etemkeskin.com\/index.php\/tr\/2021\/01\/25\/django-uygulamalarinda-excel-csv-json-gibi-farkli-formattaki-veriyi-ice-ve-disa-aktarma\/\",\"name\":\"Django Uygulamalar\\u0131nda Excel, CSV, JSON gibi Farkl\\u0131 Formattaki Veriyi \\u0130\\u00e7e ve D\\u0131\\u015fa Aktarma - blog website\",\"isPartOf\":{\"@id\":\"https:\/\/www.etemkeskin.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.etemkeskin.com\/index.php\/tr\/2021\/01\/25\/django-uygulamalarinda-excel-csv-json-gibi-farkli-formattaki-veriyi-ice-ve-disa-aktarma\/#primaryimage\"},\"datePublished\":\"2021-01-25T18:45:29+00:00\",\"dateModified\":\"2021-01-25T19:50:16+00:00\",\"author\":{\"@id\":\"https:\/\/www.etemkeskin.com\/#\/schema\/person\/dcbc30282861ce578b96a79ce8789629\"},\"description\":\"Django ile web uygulamalar\\u0131 geli\\u015ftirdi\\u011fimizde veri taban\\u0131na farkl\\u0131 formatlarda verilerimizi aktarmak veya veritaban\\u0131ndaki verileri tablo halinde elde etmek isteriz. django-import-export paketi bizim i\\u00e7in bu i\\u015flemi kolayla\\u015ft\\u0131ran bir pakettir. Paket Excel, CSV, JSON gibi farkl\\u0131 formattaki verileri desteklemektedir.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.etemkeskin.com\/index.php\/tr\/2021\/01\/25\/django-uygulamalarinda-excel-csv-json-gibi-farkli-formattaki-veriyi-ice-ve-disa-aktarma\/#breadcrumb\"},\"inLanguage\":\"tr\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.etemkeskin.com\/index.php\/tr\/2021\/01\/25\/django-uygulamalarinda-excel-csv-json-gibi-farkli-formattaki-veriyi-ice-ve-disa-aktarma\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.etemkeskin.com\/index.php\/tr\/2021\/01\/25\/django-uygulamalarinda-excel-csv-json-gibi-farkli-formattaki-veriyi-ice-ve-disa-aktarma\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Ana sayfa\",\"item\":\"https:\/\/www.etemkeskin.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Django Uygulamalar\\u0131nda Excel, CSV, JSON gibi Farkl\\u0131 Formattaki Veriyi \\u0130\\u00e7e ve D\\u0131\\u015fa Aktarma\"}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.etemkeskin.com\/#\/schema\/person\/dcbc30282861ce578b96a79ce8789629\",\"name\":\"etemkeskin\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.etemkeskin.com\/#personlogo\",\"inLanguage\":\"tr\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/6af0148b790691ed24ae245fb3dc773b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/6af0148b790691ed24ae245fb3dc773b?s=96&d=mm&r=g\",\"caption\":\"etemkeskin\"},\"url\":\"https:\/\/www.etemkeskin.com\/index.php\/author\/etemkeskinyahoo-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/www.etemkeskin.com\/index.php\/wp-json\/wp\/v2\/posts\/959"}],"collection":[{"href":"https:\/\/www.etemkeskin.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.etemkeskin.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.etemkeskin.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.etemkeskin.com\/index.php\/wp-json\/wp\/v2\/comments?post=959"}],"version-history":[{"count":44,"href":"https:\/\/www.etemkeskin.com\/index.php\/wp-json\/wp\/v2\/posts\/959\/revisions"}],"predecessor-version":[{"id":1053,"href":"https:\/\/www.etemkeskin.com\/index.php\/wp-json\/wp\/v2\/posts\/959\/revisions\/1053"}],"wp:attachment":[{"href":"https:\/\/www.etemkeskin.com\/index.php\/wp-json\/wp\/v2\/media?parent=959"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.etemkeskin.com\/index.php\/wp-json\/wp\/v2\/categories?post=959"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.etemkeskin.com\/index.php\/wp-json\/wp\/v2\/tags?post=959"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}