added admin view for User modal
This commit is contained in:
parent
346f53e917
commit
82bb188743
|
@ -10,10 +10,44 @@ from import_export import resources
|
|||
|
||||
from .models import *
|
||||
|
||||
class UserAdmin(ImportExportMixin, SimpleHistoryAdmin):
|
||||
pass
|
||||
|
||||
admin.site.register(User,UserAdmin)
|
||||
class ArrayFieldListFilter(admin.SimpleListFilter):
|
||||
"""This is a list filter based on the values
|
||||
from a model's `keywords` ArrayField. """
|
||||
|
||||
title = 'Roles'
|
||||
parameter_name = 'user_type'
|
||||
|
||||
def lookups(self, request, model_admin):
|
||||
# Very similar to our code above, but this method must return a
|
||||
# list of tuples: (lookup_value, human-readable value). These
|
||||
# appear in the admin's right sidebar
|
||||
|
||||
keywords = User.objects.values_list("user_type", flat=True)
|
||||
keywords = [(kw, kw) for sublist in keywords for kw in sublist if kw]
|
||||
keywords = sorted(set(keywords))
|
||||
return keywords
|
||||
|
||||
def queryset(self, request, queryset):
|
||||
# when a user clicks on a filter, this method gets called. The
|
||||
# provided queryset with be a queryset of Items, so we need to
|
||||
# filter that based on the clicked keyword.
|
||||
|
||||
lookup_value = self.value() # The clicked keyword. It can be None!
|
||||
if lookup_value:
|
||||
# the __contains lookup expects a list, so...
|
||||
queryset = queryset.filter(user_type__contains=[lookup_value])
|
||||
return queryset
|
||||
|
||||
|
||||
class UserAdmin(ImportExportMixin, SimpleHistoryAdmin):
|
||||
list_display = ('email', 'user_type', 'last_login_time')
|
||||
list_filter = (ArrayFieldListFilter, 'last_login_time')
|
||||
search_fields = ('email', 'user_type')
|
||||
ordering = ('email', 'user_type')
|
||||
|
||||
|
||||
admin.site.register(User, UserAdmin)
|
||||
|
||||
admin.site.site_header = "CDC Recruitment Portal"
|
||||
|
||||
|
@ -26,6 +60,7 @@ def model_admin_url(obj, name=None) -> str:
|
|||
class StudentAdmin(ImportExportMixin, SimpleHistoryAdmin):
|
||||
pass
|
||||
|
||||
|
||||
@admin.register(Student)
|
||||
class Student(StudentAdmin):
|
||||
list_display = ("roll_no", "name", "batch", "branch", "phone_number", 'can_apply')
|
||||
|
@ -44,11 +79,14 @@ class Student(StudentAdmin):
|
|||
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',
|
||||
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
|
||||
|
||||
|
@ -66,9 +104,11 @@ class PlacementApplicationResources(resources.ModelResource):
|
|||
model = PlacementApplication
|
||||
exclude = ('id', 'changed_by')
|
||||
|
||||
|
||||
class PlacementAdmin(ExportMixin, SimpleHistoryAdmin):
|
||||
resource_class = PlacementApplicationResources
|
||||
|
||||
|
||||
@admin.register(PlacementApplication)
|
||||
class PlacementApplication(PlacementAdmin):
|
||||
list_display = ('id', 'Placement', 'Student', 'selected')
|
||||
|
@ -88,9 +128,11 @@ class PrePlacementResources(resources.ModelResource):
|
|||
model = PrePlacementOffer
|
||||
exclude = ('id', 'changed_by')
|
||||
|
||||
|
||||
class PrePlacementOfferAdmin(ExportMixin, SimpleHistoryAdmin):
|
||||
resource_class = PrePlacementResources
|
||||
|
||||
|
||||
@admin.register(PrePlacementOffer)
|
||||
class PrePlacementOffer(PrePlacementOfferAdmin):
|
||||
list_display = ('company', 'Student', 'accepted')
|
||||
|
|
Loading…
Reference in New Issue