Skip to content

Commit

Permalink
faster admin view for savedrun
Browse files Browse the repository at this point in the history
  • Loading branch information
devxpy committed Feb 27, 2024
1 parent a9941ed commit 6ab6ff8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
17 changes: 13 additions & 4 deletions bots/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,16 +294,25 @@ class SavedRunAdmin(admin.ModelAdmin):
django.db.models.JSONField: {"widget": JSONEditorWidget},
}

def get_queryset(self, request):
return (
super()
.get_queryset(request)
.prefetch_related(
"parent_version",
"parent_version__published_run",
"parent_version__published_run__saved_run",
)
)

def lookup_allowed(self, key, value):
if key in ["parent_version__published_run__id__exact"]:
return True
return super().lookup_allowed(key, value)

def view_user(self, saved_run: SavedRun):
return change_obj_url(
AppUser.objects.get(uid=saved_run.uid),
label=f"{saved_run.uid}",
)
user = AppUser.objects.get(uid=saved_run.uid)
return change_obj_url(user)

view_user.short_description = "View User"

Expand Down
4 changes: 3 additions & 1 deletion daras_ai_v2/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
HASHIDS_SALT = config("HASHIDS_SALT", default="")

ALLOWED_HOSTS = ["*"]
INTERNAL_IPS = ["127.0.0.1"]
INTERNAL_IPS = ["127.0.0.1", "localhost"]
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")

# Application definition
Expand All @@ -48,6 +48,7 @@
"django.contrib.staticfiles",
"bots",
"django_extensions",
# "debug_toolbar",
# the order matters, since we want to override the admin templates
"django.forms", # needed to override admin forms
"django.contrib.admin",
Expand All @@ -67,6 +68,7 @@
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
# "debug_toolbar.middleware.DebugToolbarMiddleware",
]

ROOT_URLCONF = "gooeysite.urls"
Expand Down
3 changes: 2 additions & 1 deletion gooeysite/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
"""

from django.contrib import admin
from django.urls import path
from django.urls import path, include

urlpatterns = [
# path("__debug__/", include("debug_toolbar.urls")),
path("", admin.site.urls),
]

0 comments on commit 6ab6ff8

Please sign in to comment.