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 *
|
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"
|
admin.site.site_header = "CDC Recruitment Portal"
|
||||||
|
|
||||||
|
@ -26,6 +60,7 @@ def model_admin_url(obj, name=None) -> str:
|
||||||
class StudentAdmin(ImportExportMixin, SimpleHistoryAdmin):
|
class StudentAdmin(ImportExportMixin, SimpleHistoryAdmin):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@admin.register(Student)
|
@admin.register(Student)
|
||||||
class Student(StudentAdmin):
|
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')
|
||||||
|
@ -44,11 +79,14 @@ class Student(StudentAdmin):
|
||||||
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 PlacementResources(resources.ModelResource):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Placement
|
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')
|
'is_compensation_details_pdf', 'is_selection_procedure_details_pdf')
|
||||||
|
|
||||||
|
|
||||||
class AdminAdmin(ExportMixin, SimpleHistoryAdmin):
|
class AdminAdmin(ExportMixin, SimpleHistoryAdmin):
|
||||||
resource_class = PlacementResources
|
resource_class = PlacementResources
|
||||||
|
|
||||||
|
@ -66,9 +104,11 @@ class PlacementApplicationResources(resources.ModelResource):
|
||||||
model = PlacementApplication
|
model = PlacementApplication
|
||||||
exclude = ('id', 'changed_by')
|
exclude = ('id', 'changed_by')
|
||||||
|
|
||||||
|
|
||||||
class PlacementAdmin(ExportMixin, SimpleHistoryAdmin):
|
class PlacementAdmin(ExportMixin, SimpleHistoryAdmin):
|
||||||
resource_class = PlacementApplicationResources
|
resource_class = PlacementApplicationResources
|
||||||
|
|
||||||
|
|
||||||
@admin.register(PlacementApplication)
|
@admin.register(PlacementApplication)
|
||||||
class PlacementApplication(PlacementAdmin):
|
class PlacementApplication(PlacementAdmin):
|
||||||
list_display = ('id', 'Placement', 'Student', 'selected')
|
list_display = ('id', 'Placement', 'Student', 'selected')
|
||||||
|
@ -88,9 +128,11 @@ class PrePlacementResources(resources.ModelResource):
|
||||||
model = PrePlacementOffer
|
model = PrePlacementOffer
|
||||||
exclude = ('id', 'changed_by')
|
exclude = ('id', 'changed_by')
|
||||||
|
|
||||||
|
|
||||||
class PrePlacementOfferAdmin(ExportMixin, SimpleHistoryAdmin):
|
class PrePlacementOfferAdmin(ExportMixin, SimpleHistoryAdmin):
|
||||||
resource_class = PrePlacementResources
|
resource_class = PrePlacementResources
|
||||||
|
|
||||||
|
|
||||||
@admin.register(PrePlacementOffer)
|
@admin.register(PrePlacementOffer)
|
||||||
class PrePlacementOffer(PrePlacementOfferAdmin):
|
class PrePlacementOffer(PrePlacementOfferAdmin):
|
||||||
list_display = ('company', 'Student', 'accepted')
|
list_display = ('company', 'Student', 'accepted')
|
||||||
|
|
Loading…
Reference in New Issue