-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Management commands made for bulk dummy data addition of date times a…
…nd users and conversion of timezones from UTC to PSTQ and vice versa in bulks , date time model added
- Loading branch information
1 parent
36dc855
commit 6936e6f
Showing
1 changed file
with
55 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |