django-import-export で
マスターデータ管理生活

django-import-export で
マスターデータ管理生活

PYTHON KANSAI #02

F703b996b502414dd880bc39789faa8f?s=128

Daisuke Konishi

December 08, 2019
Tweet

Transcript

  1. EKBOHPJNQPSUFYQPSUͰ
 Ϛελʔσʔλ؅ཧੜ׆ %BJTVLF,0/*4)*

  2. %BJTVLF,0/*4)*!TLE@OX ٳ೔8FCΤϯδχΞ

  3. .FNP%SJQ IUUQTNFNPESJQOFU

  4. None
  5. EKBOHPJNQPSUFYQPSUͷ঺հ

  6. EKBOHPJNQPSUFYQPSUͷ঺հ ؅ཧը໘͔Β$47΍+40/ͳͲͷΠϯϙʔτ΍ΤΫεϙʔτΛ
 Ͱ͖ΔΑ͏ʹ͢Δ%KBOHPͷϥΠϒϥϦ w ࠩ෼ߋ৽΍มߋ෼ͷՄࢹԽΛͯ͘͠ΕΔ w *%ྻ͸ࣗ෼Ͱॻ͔ͳͯ͘΋ΠϯΫϦϝϯτͯ͘͠ΕΔ Α͏ ʹ΋Ͱ͖Δ 

    w ϦϨʔγϣϯΛҙࣝͯ͠*%Λهࡌ͢Δͷ͸ਏ͍ https://github.com/django-import-export/django-import-export
  7. ͝൧ΛऔΓࠐΉ

  8. from django.db import models class Food(models.Model): name = models.CharField('໊લ', max_length=128)

    class Meta: db_table = 'food' verbose_name = '৯΂෺' verbose_name_plural = '৯΂෺Ұཡ' def __str__(self): return(self.name) GPPENPEFMTQZ
  9. from import_export import resources from .models import Food class FoodResource(resources.ModelResource):

    class Meta: model = Food skip_unchanged = True report_skipped = False import_id_fields = ('name', ) from django.contrib import admin from import_export.admin import ImportExportModelAdmin from .foodResources import FoodResource from .models import Food @admin.register(Food) class FoodAdmin(ImportExportModelAdmin): resource_class = FoodResource GPPEBENJOQZ GPPEGPPE3FTPVSDFTQZ
  10. ؅ཧը໘ʹϘλϯ͕૿͑Δ

  11. Πϯϙʔτ࣌ʹࠩ෼දࣔ

  12. Ͳ͏࢖͍͔ͬͯ͘

  13. .FNP%SJQͷ৔߹ ίʔώʔͷσʔλͱݪ࢈ࠃͷσʔλΛεϓϨουγʔτͰ؅ཧɻ $47Ͱు͖ग़ͨ͠΋ͷΛྲྀ͠ࠐΉΑ͏ʹ͍ͯ͠·͢ɻ

  14. εΫϨΠϐϯάͨ͠σʔλΛ׆༻ Φʔϓϯσʔλ΍εΫϨΠϐϯάͨ݁͠ՌΛऔΓࠐΉ w αΠτن໿ʹ͸஫ҙ

  15. w άϥϑΛදࣔ͢ΔͳͲ7JFXΛ্ख͘࡞Δ͜ͱ͕Ͱ͖Ε͹ɺ ϒϥ΢βͰ৭Μͳਓ͕σʔλΛӾཡՄೳʹ w %KBOHP3&45'SBNFXPSLͰ+40/Λ࢖ͬͨ΍ΓऔΓ͕
 Ͱ͖ΔΑ͏ʹͳΔͷͰɺଞͷΞϓϦέʔγϣϯͱͷ࿈ܞ΋ Մೳʹ %KBOHPͰσʔλ͕ೖΕΒΕͨΒʜ