import export for data models in django admin (#138)

* import export for User and Student model

* export feature for placement, placementapplication, ppo.
This commit is contained in:
karthik mv 2022-08-11 13:02:26 +05:30 committed by GitHub
parent 91794a4174
commit 081a51c5ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 7 deletions

View File

@ -1,13 +1,19 @@
from django.contrib import admin
from simple_history.admin import SimpleHistoryAdmin
from django.contrib.admin.templatetags.admin_urls import admin_urlname
from django.shortcuts import resolve_url
from django.utils.html import format_html
from django.utils.safestring import SafeText
from simple_history.admin import SimpleHistoryAdmin
from import_export.admin import ImportExportMixin, ExportMixin
from import_export import resources
from .models import *
admin.site.register(User, SimpleHistoryAdmin)
class UserAdmin(ImportExportMixin, SimpleHistoryAdmin):
pass
admin.site.register(User,UserAdmin)
admin.site.register(Admin, SimpleHistoryAdmin)
admin.site.site_header = "CDC Recruitment Portal"
@ -18,8 +24,11 @@ def model_admin_url(obj, name=None) -> str:
return format_html('<a href="{}">{}</a>', url, name or str(obj))
class StudentAdmin(ImportExportMixin, SimpleHistoryAdmin):
pass
@admin.register(Student)
class Student(SimpleHistoryAdmin):
class Student(StudentAdmin):
list_display = ("roll_no", "name", "batch", "branch", "phone_number", 'can_apply')
search_fields = ("roll_no", "name", "phone_number")
ordering = ("roll_no", "name", "batch", "branch", "phone_number")
@ -36,17 +45,33 @@ class Student(SimpleHistoryAdmin):
queryset.update(can_apply=True)
self.message_user(request, "Registered the users")
class PlacementResources(resources.ModelResource):
class Meta:
model = Placement
exclude = ('id','changed_by', 'is_company_details_pdf', 'is_description_pdf',
'is_compensation_details_pdf', 'is_selection_procedure_details_pdf')
class AdminAdmin(ExportMixin, SimpleHistoryAdmin):
resource_class = PlacementResources
@admin.register(Placement)
class Placement(SimpleHistoryAdmin):
class Placement(AdminAdmin):
list_display = (COMPANY_NAME, CONTACT_PERSON_NAME, PHONE_NUMBER, 'tier', 'compensation_CTC')
search_fields = (COMPANY_NAME, CONTACT_PERSON_NAME)
ordering = (COMPANY_NAME, CONTACT_PERSON_NAME, 'tier', 'compensation_CTC')
list_filter = ('tier',)
class PlacementApplicationResources(resources.ModelResource):
class Meta:
model = PlacementApplication
exclude = ('id', 'changed_by')
class PlacementAdmin(ExportMixin, SimpleHistoryAdmin):
resource_class = PlacementApplicationResources
@admin.register(PlacementApplication)
class PlacementApplication(SimpleHistoryAdmin):
class PlacementApplication(PlacementAdmin):
list_display = ('id', 'Placement', 'Student', 'selected')
search_fields = ('id',)
ordering = ('id',)
@ -59,8 +84,16 @@ class PlacementApplication(SimpleHistoryAdmin):
return model_admin_url(obj.student)
class PrePlacementResources(resources.ModelResource):
class Meta:
model = PrePlacementOffer
exclude = ('id', 'changed_by')
class PrePlacementOfferAdmin(ExportMixin, SimpleHistoryAdmin):
resource_class = PrePlacementResources
@admin.register(PrePlacementOffer)
class PrePlacementOffer(SimpleHistoryAdmin):
class PrePlacementOffer(PrePlacementOfferAdmin):
list_display = ('company', 'Student', 'accepted')
search_fields = ('company',)
ordering = ('company',)

View File

@ -46,6 +46,7 @@ INSTALLED_APPS = [
'django_db_logger',
'background_task',
'simple_history',
'import_export',
]
MIDDLEWARE = [

View File

@ -5,6 +5,8 @@ certifi==2021.10.8
chardet==4.0.0
charset-normalizer==2.0.12
colorama==0.4.4
defusedxml==0.7.1
diff-match-patch==20200713
dill==0.3.5.1
dj-database-url==0.5.0
Django==3.2.13
@ -12,8 +14,10 @@ django-background-tasks==1.2.5
django-compat==1.0.15
django-cors-headers==3.11.0
django-db-logger==0.1.12
django-import-export==2.8.0
django-simple-history==3.1.1
djangorestframework==3.13.1
et-xmlfile==1.1.0
google-auth==2.6.6
gunicorn==20.1.0
idna==3.3
@ -22,7 +26,10 @@ isort==5.10.1
jsonfield==3.1.0
lazy-object-proxy==1.7.1
Markdown==3.3.6
MarkupPy==1.14
mccabe==0.7.0
odfpy==1.4.1
openpyxl==3.0.10
pdfkit==1.0.0
platformdirs==2.5.1
psycopg2-binary==2.9.3
@ -32,14 +39,18 @@ PyJWT==2.4.0
pylint==2.13.5
python-dotenv==0.20.0
pytz==2022.1
PyYAML==6.0
requests==2.27.1
rsa==4.8
six==1.16.0
sqlparse==0.4.2
tablib==3.2.1
toml==0.10.2
tomli==2.0.1
typing-extensions==4.1.1
typing_extensions==4.1.1
urllib3==1.26.9
whitenoise==6.0.0
wrapt==1.14.0
xlrd==2.0.1
xlwt==1.3.0
zipp==3.8.0