Skip to content

Commit

Permalink
Management commands made for bulk dummy data addition of date times a…
Browse files Browse the repository at this point in the history
…nd users and conversion of timezones from UTC to PSTQ and vice versa in bulks , date time model added
  • Loading branch information
Abdul-Muqadim-Arbisoft committed Sep 5, 2023
1 parent 36dc855 commit 6936e6f
Showing 1 changed file with 55 additions and 5 deletions.
60 changes: 55 additions & 5 deletions user/admin.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,73 @@
from django.contrib.auth.admin import UserAdmin
from .models import CustomUser, DateTimeRecord
from .admin_site import admin_site
from django.contrib import admin


def make_active(modeladmin, request, queryset):
"""
Set the `is_active` attribute of the selected users to True.
"""
queryset.update(is_active=True)


make_active.short_description = "Mark selected users as active"


def make_inactive(modeladmin, request, queryset):
"""
Set the `is_active` attribute of the selected users to False.
"""
queryset.update(is_active=False)


make_inactive.short_description = "Mark selected users as inactive"


class CustomUserAdmin(UserAdmin):
"""
Admin customization for the CustomUser model.
This admin combines functionalities from two previous admin customizations:
1. It inherits from UserAdmin for user-specific functionalities.
2. It defines fields, filters, actions, and displays that cater to the specific attributes and requirements of CustomUser.
"""

add_fieldsets = (
(None, {
'classes': ('wide',),
'fields': ('username', 'email', 'description', 'father_name', 'password1', 'password2'),
# include other fields of CustomUser
}),
)

fieldsets = (
(None, {'fields': ('username', 'email', 'description', 'father_name', 'password')}),
# include other fields of CustomUser
(None, {'fields': (
'username', 'email', 'description', 'father_name', 'password', 'software_engineering_experience',
'last_profile_update', 'is_active', 'is_staff')}),
)
list_display = ('email', 'description', 'username', 'father_name') # display fields in the user list page

list_display = (
'email', 'description', 'username', 'father_name', 'first_name', 'last_name', 'software_engineering_experience',
'last_profile_update')
search_fields = ('email', 'first_name', 'last_name', 'father_name')
list_filter = ('is_active', 'is_staff', 'software_engineering_experience')
actions = [make_active, make_inactive]


admin_site.register(CustomUser, CustomUserAdmin)

admin_site.register(DateTimeRecord)

class DateTimeRecordAdmin(admin.ModelAdmin):
"""
Admin customization for the DateTimeRecord model.
This customization defines the fields to be displayed in list view,
fields available for search, and filters to narrow down displayed records.
"""

list_display = ('datetime', 'converted_to_utc')
search_fields = ('datetime',)
list_filter = ('converted_to_utc',)


admin_site.register(DateTimeRecord, DateTimeRecordAdmin)

0 comments on commit 6936e6f

Please sign in to comment.