Skip to content

Commit

Permalink
Django-admin-import-export package added.
Browse files Browse the repository at this point in the history
  • Loading branch information
krishnamadhavan committed Sep 14, 2019
1 parent ffd1ed5 commit ea7d97a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
28 changes: 28 additions & 0 deletions questionnaire/admin.py
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 3 additions & 0 deletions questionnaire/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
13 changes: 12 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion survey_app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
'questionnaire.apps.QuestionnaireConfig',
'rest_framework',
'admin_reorder',
'import_export',
]

MIDDLEWARE = [
Expand Down Expand Up @@ -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')}

)

Expand Down

0 comments on commit ea7d97a

Please sign in to comment.