From ea7d97a6433fc756088630e35219a9e47768c0cc Mon Sep 17 00:00:00 2001 From: Krishna Madhavan Date: Sat, 14 Sep 2019 13:42:37 +0530 Subject: [PATCH] Django-admin-import-export package added. --- questionnaire/admin.py | 28 ++++++++++++++++++++++++++++ questionnaire/models.py | 3 +++ requirements.txt | 13 ++++++++++++- survey_app/settings.py | 3 ++- 4 files changed, 45 insertions(+), 2 deletions(-) diff --git a/questionnaire/admin.py b/questionnaire/admin.py index c7a959e..ba3937a 100755 --- a/questionnaire/admin.py +++ b/questionnaire/admin.py @@ -1,3 +1,31 @@ from django.contrib import admin +from import_export import resources +from import_export.admin import ImportExportModelAdmin +from questionnaire import models + +class SurveyResource(resources.ModelResource): + class Meta: + model = models.Survey + fields = [field.name for field in models.Survey._meta.fields] + + +class SurveyAdmin(ImportExportModelAdmin): + resource_class = SurveyResource + list_display = [field.name for field in models.Survey._meta.fields] + + +class FamilyDetailsResource(resources.ModelResource): + class Meta: + model = models.FamilyDetails + fields = [field.name for field in models.FamilyDetails._meta.fields] + + +class FamilyDetailsAdmin(ImportExportModelAdmin): + resource_class = FamilyDetailsResource + list_display = [field.name for field in models.FamilyDetails._meta.fields] + + +admin.site.register(models.Survey, SurveyAdmin) +admin.site.register(models.FamilyDetails, FamilyDetailsAdmin) diff --git a/questionnaire/models.py b/questionnaire/models.py index 132a906..5c98331 100755 --- a/questionnaire/models.py +++ b/questionnaire/models.py @@ -305,6 +305,9 @@ class Meta: verbose_name = _('Survey') verbose_name_plural = _('Surveys') + def __str__(self): + return str(self.pk) + class FamilyDetails(models.Model): relationship_choices = (('01-Head', '01-Head'), ('02-Wife/Husband', '02-Wife/Husband'), ('03-Son/Daughter', diff --git a/requirements.txt b/requirements.txt index b1ff8e9..d3be23a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,11 +1,22 @@ +backports.csv==1.0.7 +defusedxml==0.6.0 +diff-match-patch==20181111 dj-database-url==0.5.0 Django==2.2.5 +django-import-export==1.2.0 django-modeladmin-reorder==0.3.1 djangorestframework==3.10.3 +et-xmlfile==1.0.1 gunicorn==19.9.0 +jdcal==1.4.1 mysqlclient==1.4.2.post1 +odfpy==1.4.0 +openpyxl==2.6.3 python-decouple==3.1 pytz==2019.2 +PyYAML==5.1.2 sqlparse==0.3.0 +tablib==0.13.0 whitenoise==4.1.3 -psycopg2==2.8.3 +xlrd==1.2.0 +xlwt==1.3.0 diff --git a/survey_app/settings.py b/survey_app/settings.py index 469f8c6..2a0a1d6 100755 --- a/survey_app/settings.py +++ b/survey_app/settings.py @@ -45,6 +45,7 @@ 'questionnaire.apps.QuestionnaireConfig', 'rest_framework', 'admin_reorder', + 'import_export', ] MIDDLEWARE = [ @@ -139,8 +140,8 @@ # https://pypi.org/project/django-modeladmin-reorder/ ADMIN_REORDER = ( - # Rename app {'app': 'auth', 'models': ('auth.User',)}, + {'app': 'questionnaire', 'models': ('questionnaire.Survey', 'questionnaire.FamilyDetails')} )