Skip to content

Commit

Permalink
add handle<>workspace connection to admin pages
Browse files Browse the repository at this point in the history
  • Loading branch information
nikochiko committed Jan 8, 2025
1 parent b989d96 commit d876cca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 8 additions & 4 deletions handles/admin.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
from django.contrib import admin

from app_users.admin import AppUserAdmin
from workspaces.admin import WorkspaceAdmin
from .models import Handle


@admin.register(Handle)
class HandleAdmin(admin.ModelAdmin):
search_fields = ["name", "redirect_url"] + [
f"user__{field}" for field in AppUserAdmin.search_fields
]
readonly_fields = ["user", "created_at", "updated_at"]
search_fields = (
["name", "redirect_url"]
+ [f"user__{field}" for field in AppUserAdmin.search_fields]
+ [f"workspace__{field}" for field in WorkspaceAdmin.search_fields]
)
readonly_fields = ["user", "workspace", "created_at", "updated_at"]

list_filter = [
("user", admin.EmptyFieldListFilter),
("workspace", admin.EmptyFieldListFilter),
("redirect_url", admin.EmptyFieldListFilter),
]
6 changes: 4 additions & 2 deletions workspaces/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class WorkspaceAdmin(SafeDeleteAdmin):
"display_name",
"is_personal",
"created_by",
"handle",
"is_paying",
"balance",
"subscription",
Expand All @@ -73,6 +74,7 @@ class WorkspaceAdmin(SafeDeleteAdmin):
"name",
"description",
"domain_name",
"handle",
"created_by",
"is_personal",
("is_paying", "stripe_customer_id"),
Expand All @@ -81,7 +83,7 @@ class WorkspaceAdmin(SafeDeleteAdmin):
("created_at", "updated_at"),
"open_in_stripe",
]
search_fields = ["name", "created_by__display_name", "domain_name"]
search_fields = ["name", "created_by__display_name", "domain_name", "handle__name"]
readonly_fields = [
"is_personal",
"created_at",
Expand All @@ -93,7 +95,7 @@ class WorkspaceAdmin(SafeDeleteAdmin):
]
inlines = [WorkspaceMembershipInline, WorkspaceInviteInline]
ordering = ["-created_at"]
autocomplete_fields = ["created_by"]
autocomplete_fields = ["created_by", "handle"]

def get_form(self, request, obj=None, change=False, **kwargs):
self.obj = obj
Expand Down

0 comments on commit d876cca

Please sign in to comment.