Skip to content

Commit

Permalink
feat: improve account admin to show subscription (#555)
Browse files Browse the repository at this point in the history
  • Loading branch information
vncsna authored Feb 2, 2024
1 parent d18dba0 commit 76ddfa2
Showing 1 changed file with 16 additions and 23 deletions.
39 changes: 16 additions & 23 deletions bd_api/apps/account/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.http import HttpRequest
from faker import Faker

from bd_api.apps.account.models import Account, BDGroup, BDGroupRole, BDRole, Career, Subscription
from bd_api.apps.account.models import Account, Career, Subscription
from bd_api.apps.account.tasks import sync_subscription_task


Expand Down Expand Up @@ -117,15 +117,16 @@ def __init__(self, *args, **kwargs):
user_permissions.queryset = user_permissions.queryset.select_related("content_type")


class BDGroupRoleInline(admin.TabularInline):
model = BDGroupRole
extra = 1


class CareerInline(admin.StackedInline):
model = Career
extra = 1
ordering = ["start_at"]
extra = 0
ordering = ["-start_at"]


class SubscriptionInline(admin.StackedInline):
model = Subscription
extra = 0
ordering = ["-created_at"]


class AccountAdmin(BaseAccountAdmin):
Expand All @@ -140,10 +141,11 @@ class AccountAdmin(BaseAccountAdmin):
"username",
"get_full_name",
"get_organization",
"created_at",
"is_admin",
)
readonly_fields = ("uuid", "created_at", "updated_at", "deleted_at")
list_filter = ("is_admin", "profile")
list_filter = ("is_superuser", "is_admin", "profile")
fieldsets = (
(
None,
Expand Down Expand Up @@ -221,24 +223,17 @@ class AccountAdmin(BaseAccountAdmin):
},
),
)
search_fields = ("email",)
ordering = ("email",)
inlines = (CareerInline,)
search_fields = ("email", "full_name")
ordering = ["-created_at"]
inlines = (CareerInline, SubscriptionInline)
filter_horizontal = ()


class CareerAdmin(admin.ModelAdmin):
list_display = ("account", "team", "level", "role", "start_at", "end_at")
search_fields = ("account", "team")
readonly_fields = ("created_at", "updated_at")
ordering = ("account", "start_at")


class BDGroupAdmin(admin.ModelAdmin):
inlines = (BDGroupRoleInline,)
list_display = ("name", "description")
search_fields = ("name", "description")
ordering = ("name",)
ordering = ["account", "start_at"]


class SubscriptionAdmin(admin.ModelAdmin):
Expand All @@ -255,14 +250,12 @@ class SubscriptionAdmin(admin.ModelAdmin):
"admin",
"subscription",
)
ordering = ("admin__email", "subscription__created")
ordering = ["admin__email", "subscription__created"]

def has_add_permission(self, request: HttpRequest):
return False


admin.site.register(Account, AccountAdmin)
admin.site.register(Career, CareerAdmin)
admin.site.register(BDRole)
admin.site.register(BDGroup, BDGroupAdmin)
admin.site.register(Subscription, SubscriptionAdmin)

0 comments on commit 76ddfa2

Please sign in to comment.