Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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

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

PYTHON KANSAI #02

Daisuke Konishi

December 08, 2019
Tweet

More Decks by Daisuke Konishi

Other Decks in Programming

Transcript

  1. EKBOHPJNQPSUFYQPSUͰ

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

    View full-size slide

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

    View full-size slide

  3. .FNP%SJQ
    IUUQTNFNPESJQOFU

    View full-size slide

  4. EKBOHPJNQPSUFYQPSUͷ঺հ

    View full-size slide

  5. EKBOHPJNQPSUFYQPSUͷ঺հ
    ؅ཧը໘͔Β$47΍+40/ͳͲͷΠϯϙʔτ΍ΤΫεϙʔτΛ

    Ͱ͖ΔΑ͏ʹ͢Δ%KBOHPͷϥΠϒϥϦ
    w ࠩ෼ߋ৽΍มߋ෼ͷՄࢹԽΛͯ͘͠ΕΔ
    w *%ྻ͸ࣗ෼Ͱॻ͔ͳͯ͘΋ΠϯΫϦϝϯτͯ͘͠ΕΔ Α͏
    ʹ΋Ͱ͖Δ

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

    View full-size slide

  6. ͝൧ΛऔΓࠐΉ

    View full-size slide

  7. 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

    View full-size slide

  8. 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

    View full-size slide

  9. ؅ཧը໘ʹϘλϯ͕૿͑Δ

    View full-size slide

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

    View full-size slide

  11. Ͳ͏࢖͍͔ͬͯ͘

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  14. w άϥϑΛදࣔ͢ΔͳͲ7JFXΛ্ख͘࡞Δ͜ͱ͕Ͱ͖Ε͹ɺ
    ϒϥ΢βͰ৭Μͳਓ͕σʔλΛӾཡՄೳʹ
    w %KBOHP3&45'SBNFXPSLͰ+40/Λ࢖ͬͨ΍ΓऔΓ͕

    Ͱ͖ΔΑ͏ʹͳΔͷͰɺଞͷΞϓϦέʔγϣϯͱͷ࿈ܞ΋
    Մೳʹ
    %KBOHPͰσʔλ͕ೖΕΒΕͨΒʜ

    View full-size slide