diff --git a/app/admin.py b/app/admin.py index 8348cae..25ce72d 100644 --- a/app/admin.py +++ b/app/admin.py @@ -2,6 +2,24 @@ # Register your models here. from . models import tutorial, tag +from import_export.admin import ImportExportModelAdmin +from import_export import resources, fields +from import_export.widgets import ManyToManyWidget admin.site.register(tag) -admin.site.register(tutorial) \ No newline at end of file + +class TutorialResource(resources.ModelResource): + tags = fields.Field( + column_name='tags', + attribute='tags', + widget=ManyToManyWidget(tag, ',', 'name')) + class Meta: + model = tutorial + exclude = ('id',) + export_order = ('title', 'link', 'tags', 'category', 'created_date') + import_id_fields = ('title', 'link') + + +@admin.register(tutorial) +class TutorialAdmin(ImportExportModelAdmin): + resource_class = TutorialResource \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 39bb75e..207a734 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,5 @@ requests==2.18.4 beautifulsoup4==4.7.1 lxml==4.4.0 djangorestframework==3.10.0 -python-dotenv==0.10.3 \ No newline at end of file +python-dotenv==0.10.3 +django-import-export==1.2.0 \ No newline at end of file diff --git a/tutorialdb/settings.py b/tutorialdb/settings.py index 292358a..e2b0db8 100644 --- a/tutorialdb/settings.py +++ b/tutorialdb/settings.py @@ -28,6 +28,7 @@ 'app', 'api', 'taggie', + 'import_export', ] REST_FRAMEWORK = {