Skip to content

Commit

Permalink
FEA: Use django-unfold as alternative admin
Browse files Browse the repository at this point in the history
  • Loading branch information
thclark committed Nov 28, 2023
1 parent 0a0aca1 commit 1b693b5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "django-gcp"
version = "0.10.6"
version = "0.11.0"
description = "Utilities to run Django on Google Cloud Platform"
authors = ["Tom Clark"]
license = "MIT"
Expand Down
41 changes: 30 additions & 11 deletions tests/server/example/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from django.contrib import admin
from django.conf import settings
from django.contrib import admin as django_admin
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from django.contrib.auth.models import User
from unfold import admin as unfold_admin

from tests.server.example.models import (
ExampleBlankBlobFieldModel,
Expand All @@ -9,28 +13,43 @@
)


class ExampleStorageModelAdmin(admin.ModelAdmin):
# Allow switching between unfold and regular, for development purposes, by simply adding unfold to installed apps
if "unfold" in settings.INSTALLED_APPS:
ModelAdmin = unfold_admin.ModelAdmin
django_admin.site.unregister(User)

#
class UserAdmin(BaseUserAdmin, ModelAdmin):
"""Allows working with user admin for unfold and for regular django"""

django_admin.site.register(User, UserAdmin)

else:
ModelAdmin = django_admin.ModelAdmin


class ExampleStorageModelAdmin(ModelAdmin):
"""A basic admin panel to demonstrate normal storage behaviour"""


class ExampleBlobFieldModelAdmin(admin.ModelAdmin):
class ExampleBlobFieldModelAdmin(ModelAdmin):
"""A basic admin panel to demonstrate the direct upload storage behaviour"""


class ExampleBlankBlobFieldModelAdmin(admin.ModelAdmin):
class ExampleBlankBlobFieldModelAdmin(ModelAdmin):
"""A basic admin panel to demonstrate the direct upload storage behaviour where blank=True"""


class ExampleUneditableBlobFieldModelAdmin(admin.ModelAdmin):
class ExampleUneditableBlobFieldModelAdmin(ModelAdmin):
"""A basic admin panel to demonstrate the direct upload storage behaviour where blank=True"""


class ExampleMultipleBlobFieldModelAdmin(admin.ModelAdmin):
class ExampleMultipleBlobFieldModelAdmin(ModelAdmin):
"""A basic admin panel to demonstrate the direct upload storage behaviour where multiple blobfields are used"""


admin.site.register(ExampleStorageModel, ExampleStorageModelAdmin)
admin.site.register(ExampleBlobFieldModel, ExampleBlobFieldModelAdmin)
admin.site.register(ExampleBlankBlobFieldModel, ExampleBlankBlobFieldModelAdmin)
admin.site.register(ExampleUneditableBlobFieldModel, ExampleUneditableBlobFieldModelAdmin)
admin.site.register(ExampleMultipleBlobFieldModel, ExampleMultipleBlobFieldModelAdmin)
django_admin.site.register(ExampleStorageModel, ExampleStorageModelAdmin)
django_admin.site.register(ExampleBlobFieldModel, ExampleBlobFieldModelAdmin)
django_admin.site.register(ExampleBlankBlobFieldModel, ExampleBlankBlobFieldModelAdmin)
django_admin.site.register(ExampleUneditableBlobFieldModel, ExampleUneditableBlobFieldModelAdmin)
django_admin.site.register(ExampleMultipleBlobFieldModel, ExampleMultipleBlobFieldModelAdmin)
1 change: 1 addition & 0 deletions tests/server/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def get_db_conf():
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"unfold", # <---- COMMENT THIS OUT AND REBOOT SERVER TO DEVELOP ON ORIGINAL DJANGO ADMIN
"django.contrib.admin",
"django.contrib.messages",
"django.contrib.staticfiles",
Expand Down

0 comments on commit 1b693b5

Please sign in to comment.