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:
parent
91794a4174
commit
081a51c5ed
|
@ -1,13 +1,19 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from simple_history.admin import SimpleHistoryAdmin
|
|
||||||
from django.contrib.admin.templatetags.admin_urls import admin_urlname
|
from django.contrib.admin.templatetags.admin_urls import admin_urlname
|
||||||
from django.shortcuts import resolve_url
|
from django.shortcuts import resolve_url
|
||||||
from django.utils.html import format_html
|
from django.utils.html import format_html
|
||||||
from django.utils.safestring import SafeText
|
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 *
|
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.register(Admin, SimpleHistoryAdmin)
|
||||||
|
|
||||||
admin.site.site_header = "CDC Recruitment Portal"
|
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))
|
return format_html('<a href="{}">{}</a>', url, name or str(obj))
|
||||||
|
|
||||||
|
|
||||||
|
class StudentAdmin(ImportExportMixin, SimpleHistoryAdmin):
|
||||||
|
pass
|
||||||
|
|
||||||
@admin.register(Student)
|
@admin.register(Student)
|
||||||
class Student(SimpleHistoryAdmin):
|
class Student(StudentAdmin):
|
||||||
list_display = ("roll_no", "name", "batch", "branch", "phone_number", 'can_apply')
|
list_display = ("roll_no", "name", "batch", "branch", "phone_number", 'can_apply')
|
||||||
search_fields = ("roll_no", "name", "phone_number")
|
search_fields = ("roll_no", "name", "phone_number")
|
||||||
ordering = ("roll_no", "name", "batch", "branch", "phone_number")
|
ordering = ("roll_no", "name", "batch", "branch", "phone_number")
|
||||||
|
@ -36,17 +45,33 @@ class Student(SimpleHistoryAdmin):
|
||||||
queryset.update(can_apply=True)
|
queryset.update(can_apply=True)
|
||||||
self.message_user(request, "Registered the users")
|
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)
|
@admin.register(Placement)
|
||||||
class Placement(SimpleHistoryAdmin):
|
class Placement(AdminAdmin):
|
||||||
list_display = (COMPANY_NAME, CONTACT_PERSON_NAME, PHONE_NUMBER, 'tier', 'compensation_CTC')
|
list_display = (COMPANY_NAME, CONTACT_PERSON_NAME, PHONE_NUMBER, 'tier', 'compensation_CTC')
|
||||||
search_fields = (COMPANY_NAME, CONTACT_PERSON_NAME)
|
search_fields = (COMPANY_NAME, CONTACT_PERSON_NAME)
|
||||||
ordering = (COMPANY_NAME, CONTACT_PERSON_NAME, 'tier', 'compensation_CTC')
|
ordering = (COMPANY_NAME, CONTACT_PERSON_NAME, 'tier', 'compensation_CTC')
|
||||||
list_filter = ('tier',)
|
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)
|
@admin.register(PlacementApplication)
|
||||||
class PlacementApplication(SimpleHistoryAdmin):
|
class PlacementApplication(PlacementAdmin):
|
||||||
list_display = ('id', 'Placement', 'Student', 'selected')
|
list_display = ('id', 'Placement', 'Student', 'selected')
|
||||||
search_fields = ('id',)
|
search_fields = ('id',)
|
||||||
ordering = ('id',)
|
ordering = ('id',)
|
||||||
|
@ -59,8 +84,16 @@ class PlacementApplication(SimpleHistoryAdmin):
|
||||||
return model_admin_url(obj.student)
|
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)
|
@admin.register(PrePlacementOffer)
|
||||||
class PrePlacementOffer(SimpleHistoryAdmin):
|
class PrePlacementOffer(PrePlacementOfferAdmin):
|
||||||
list_display = ('company', 'Student', 'accepted')
|
list_display = ('company', 'Student', 'accepted')
|
||||||
search_fields = ('company',)
|
search_fields = ('company',)
|
||||||
ordering = ('company',)
|
ordering = ('company',)
|
||||||
|
|
|
@ -46,6 +46,7 @@ INSTALLED_APPS = [
|
||||||
'django_db_logger',
|
'django_db_logger',
|
||||||
'background_task',
|
'background_task',
|
||||||
'simple_history',
|
'simple_history',
|
||||||
|
'import_export',
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
|
|
|
@ -5,6 +5,8 @@ certifi==2021.10.8
|
||||||
chardet==4.0.0
|
chardet==4.0.0
|
||||||
charset-normalizer==2.0.12
|
charset-normalizer==2.0.12
|
||||||
colorama==0.4.4
|
colorama==0.4.4
|
||||||
|
defusedxml==0.7.1
|
||||||
|
diff-match-patch==20200713
|
||||||
dill==0.3.5.1
|
dill==0.3.5.1
|
||||||
dj-database-url==0.5.0
|
dj-database-url==0.5.0
|
||||||
Django==3.2.13
|
Django==3.2.13
|
||||||
|
@ -12,8 +14,10 @@ django-background-tasks==1.2.5
|
||||||
django-compat==1.0.15
|
django-compat==1.0.15
|
||||||
django-cors-headers==3.11.0
|
django-cors-headers==3.11.0
|
||||||
django-db-logger==0.1.12
|
django-db-logger==0.1.12
|
||||||
|
django-import-export==2.8.0
|
||||||
django-simple-history==3.1.1
|
django-simple-history==3.1.1
|
||||||
djangorestframework==3.13.1
|
djangorestframework==3.13.1
|
||||||
|
et-xmlfile==1.1.0
|
||||||
google-auth==2.6.6
|
google-auth==2.6.6
|
||||||
gunicorn==20.1.0
|
gunicorn==20.1.0
|
||||||
idna==3.3
|
idna==3.3
|
||||||
|
@ -22,7 +26,10 @@ isort==5.10.1
|
||||||
jsonfield==3.1.0
|
jsonfield==3.1.0
|
||||||
lazy-object-proxy==1.7.1
|
lazy-object-proxy==1.7.1
|
||||||
Markdown==3.3.6
|
Markdown==3.3.6
|
||||||
|
MarkupPy==1.14
|
||||||
mccabe==0.7.0
|
mccabe==0.7.0
|
||||||
|
odfpy==1.4.1
|
||||||
|
openpyxl==3.0.10
|
||||||
pdfkit==1.0.0
|
pdfkit==1.0.0
|
||||||
platformdirs==2.5.1
|
platformdirs==2.5.1
|
||||||
psycopg2-binary==2.9.3
|
psycopg2-binary==2.9.3
|
||||||
|
@ -32,14 +39,18 @@ PyJWT==2.4.0
|
||||||
pylint==2.13.5
|
pylint==2.13.5
|
||||||
python-dotenv==0.20.0
|
python-dotenv==0.20.0
|
||||||
pytz==2022.1
|
pytz==2022.1
|
||||||
|
PyYAML==6.0
|
||||||
requests==2.27.1
|
requests==2.27.1
|
||||||
rsa==4.8
|
rsa==4.8
|
||||||
six==1.16.0
|
six==1.16.0
|
||||||
sqlparse==0.4.2
|
sqlparse==0.4.2
|
||||||
|
tablib==3.2.1
|
||||||
toml==0.10.2
|
toml==0.10.2
|
||||||
tomli==2.0.1
|
tomli==2.0.1
|
||||||
typing-extensions==4.1.1
|
typing_extensions==4.1.1
|
||||||
urllib3==1.26.9
|
urllib3==1.26.9
|
||||||
whitenoise==6.0.0
|
whitenoise==6.0.0
|
||||||
wrapt==1.14.0
|
wrapt==1.14.0
|
||||||
|
xlrd==2.0.1
|
||||||
|
xlwt==1.3.0
|
||||||
zipp==3.8.0
|
zipp==3.8.0
|
||||||
|
|
Loading…
Reference in New Issue