Skip to content

Commit 7d88b18

Browse files
committed
adevanced update admin panel
1 parent b2d5681 commit 7d88b18

11 files changed

+1081
-13
lines changed

apps/blog/admin.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from django.contrib import admin
22
from .models import Post, PostComment, PostLike, PostDislike, PostCommentLike
33

4+
from unfold.admin import ModelAdmin
45

56
@admin.register(Post)
6-
class PostAdmin(admin.ModelAdmin):
7+
class PostAdmin(ModelAdmin):
78
list_display = ["title", "content", "author", "is_active"]
89
search_fields = ["title", "content"]
910
list_filter = ["author", "is_active"]
@@ -12,20 +13,20 @@ class PostAdmin(admin.ModelAdmin):
1213

1314

1415
@admin.register(PostComment)
15-
class PostCommentAdmin(admin.ModelAdmin):
16+
class PostCommentAdmin(ModelAdmin):
1617
pass
1718

1819

1920
@admin.register(PostLike)
20-
class PostLikeAdmin(admin.ModelAdmin):
21+
class PostLikeAdmin(ModelAdmin):
2122
pass
2223

2324

2425
@admin.register(PostDislike)
25-
class PostDislike(admin.ModelAdmin):
26+
class PostDislike(ModelAdmin):
2627
pass
2728

2829

2930
@admin.register(PostCommentLike)
30-
class PostCommentLikeAdmin(admin.ModelAdmin):
31+
class PostCommentLikeAdmin(ModelAdmin):
3132
pass

apps/users/admin.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from django.contrib import admin
2+
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
23
from .models import User, UserProfile
34

5+
from unfold.admin import ModelAdmin
46

57
@admin.register(User)
6-
class UserAdmin(admin.ModelAdmin):
8+
class UserAdmin(ModelAdmin):
79
list_display = ["username", "post_count"]
810
search_fields = ["first_name", "last_name", "username"]
911
list_display_links = ["username"]
@@ -13,5 +15,5 @@ def get_post_count(self):
1315

1416

1517
@admin.register(UserProfile)
16-
class UserProfileAdmin(admin.ModelAdmin):
18+
class UserProfileAdmin(ModelAdmin):
1719
pass

core/config/unfold.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
from django.templatetags.static import static
2+
3+
from . import unfold_navigation as navigation
4+
5+
6+
UNFOLD = {
7+
"SITE_TITLE": "Akromjon BLOG",
8+
"SITE_HEADER": "Akromjon BLOG",
9+
"SITE_URL": "/",
10+
"SITE_ICON": {
11+
"light": lambda request: static("images/django-logo.png"),
12+
"dark": lambda request: static("images/django-logo.png"),
13+
},
14+
"SITE_FAVICONS": [
15+
{
16+
"rel": "icon",
17+
"sizes": "32x32",
18+
"type": "image/svg+xml",
19+
"href": lambda request: static("images/django-logo.png"),
20+
},
21+
],
22+
"SITE_SYMBOL": "speed",
23+
"SHOW_HISTORY": True,
24+
"SHOW_VIEW_ON_SITE": True,
25+
"STYLES": [
26+
lambda request: static("css/tailwind.css"),
27+
],
28+
"LOGIN": {
29+
"image": lambda request: static("images/login.jpg"),
30+
},
31+
"COLORS": {
32+
"font": {
33+
"subtle-light": "107 114 128",
34+
"subtle-dark": "156 163 175",
35+
"default-light": "75 85 99",
36+
"default-dark": "209 213 219",
37+
"important-light": "17 24 39",
38+
"important-dark": "243 244 246",
39+
},
40+
"primary": {
41+
"50": "65 144 176",
42+
"100": "65 144 176",
43+
"200": "65 144 176",
44+
"300": "65 144 176",
45+
"400": "65 144 176",
46+
"500": "65 144 176",
47+
"600": "65 144 176",
48+
"700": "65 144 176",
49+
"800": "65 144 176",
50+
"900": "65 144 176",
51+
"950": "65 144 176",
52+
},
53+
},
54+
"EXTENSIONS": {
55+
"modeltranslation": {
56+
"flags": {
57+
"uz": "uz",
58+
"ru": "🇷🇺",
59+
}
60+
},
61+
},
62+
"SIDEBAR": {
63+
"show_search": True,
64+
"show_all_applications": True,
65+
"navigation": navigation.PAGES
66+
}
67+
}

core/config/unfold_navigation.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from django.urls import reverse_lazy
2+
from django.utils.translation import gettext_lazy as _
3+
4+
5+
def user_has_group_or_permission(user, permission):
6+
if user.is_superuser:
7+
return True
8+
9+
group_names = user.groups.values_list("name", flat=True)
10+
if not group_names:
11+
return True
12+
13+
return user.groups.filter(permissions__codename=permission).exists()
14+
15+
16+
PAGES = [
17+
{
18+
"seperator": True,
19+
"items": [
20+
{
21+
"title": _("Home"),
22+
"icon": "home",
23+
"link": reverse_lazy("admin:index"),
24+
},
25+
],
26+
},
27+
{
28+
"seperator": True,
29+
"title": _("Users"),
30+
"items": [
31+
{
32+
"title": _("Groups"),
33+
"icon": "person_add",
34+
"link": reverse_lazy("admin:auth_group_changelist"),
35+
"permission": lambda request: user_has_group_or_permission(
36+
request.user, "view_group",
37+
),
38+
},
39+
{
40+
"title": _("Users"),
41+
"icon": "person_add",
42+
"link": reverse_lazy("admin:users_user_changelist"),
43+
"permission": lambda request: user_has_group_or_permission(
44+
request.user, "view_user",
45+
),
46+
},
47+
],
48+
},
49+
]

core/settings/base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
ALLOWED_HOSTS = str(os.getenv("ALLOWED_HOSTS")).split(",")
2020

2121

22-
INSTALLED_APPS = DEFAULT_APPS + PROJECT_APPS + THIRD_PARTY_APPS # NOQA
22+
INSTALLED_APPS = THIRD_PARTY_APPS + DEFAULT_APPS + PROJECT_APPS # NOQA
2323

2424

2525
MIDDLEWARE = [
@@ -101,16 +101,16 @@
101101
LOGIN_REDIRECT_URL = "/"
102102

103103
STATIC_URL = "static/"
104-
STATIC_ROOT = BASE_DIR.joinpath("staticfiles")
105-
STATICFILES_DIRS = [BASE_DIR.joinpath("static")]
104+
STATICFILES_DIRS = [str(BASE_DIR.joinpath("static"))]
105+
STATIC_ROOT = str(BASE_DIR.joinpath("staticfiles"))
106106

107107
# AUTHENTICATION_BACKENDS = (
108108
# 'apps.users.authentication.JWTAdminAuthentication',
109109
# 'django.contrib.auth.backends.ModelBackend',
110110
# )
111111

112112
MEDIA_URL = "media/"
113-
MEDIA_ROOT = BASE_DIR.joinpath("media/")
113+
MEDIA_ROOT = str(BASE_DIR.joinpath("media/"))
114114

115115
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
116116

core/urls.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,17 @@
2323
}
2424

2525
# URLs
26-
urlpatterns = i18n_patterns(
26+
urlpatterns = [
2727
path("admin/", admin.site.urls),
2828
path("i18n", include("django.conf.urls.i18n")),
29+
path("rosetta/", include("rosetta.urls")),
30+
]
31+
32+
# Translated urls
33+
urlpatterns += i18n_patterns(
2934
path("", include("apps.blog.urls", namespace="blog")),
3035
path("users/", include("apps.users.urls", namespace="users")),
3136
path("robots.txt", TemplateView.as_view(template_name="bunin/robots.txt")),
32-
path("rosetta/", include("rosetta.urls")),
3337
path(
3438
"sitemap.xml",
3539
sitemap,

media/avatars/1727198193049.jpg

15.9 KB
Loading

0 commit comments

Comments
 (0)