From 149d2037a576c52f30f80835e89ca988701b2233 Mon Sep 17 00:00:00 2001
From: zhangxiaoyong <787819815@qq.com>
Date: Thu, 23 Feb 2023 03:07:49 +0000
Subject: [PATCH] 添加后台修改模版

---
 museum/backend/templates/wagtailadmin/userbar/base.html |    6 ++
 museum/backend/templates/wagtailadmin/home.html         |    3 +
 museum/base/migrations/__init__.py                      |    0 
 museum/base/tests.py                                    |    3 +
 museum/backend/models.py                                |   51 +++++++++++++++++
 museum/backend/tests.py                                 |    3 +
 museum/backend/wagtail_hooks.py                         |   58 +++++++++++++++++++
 museum/backend/views.py                                 |    3 +
 museum/settings/base.py                                 |    2 
 museum/backend/__init__.py                              |    0 
 museum/backend/templates/wagtailadmin/404.html          |    6 ++
 museum/backend/admin.py                                 |    3 +
 museum/base/apps.py                                     |    6 ++
 museum/base/admin.py                                    |    3 +
 museum/backend/templates/wagtailadmin/login.html        |    3 +
 museum/base/models.py                                   |    3 +
 museum/backend/migrations/__init__.py                   |    0 
 museum/base/__init__.py                                 |    0 
 museum/backend/apps.py                                  |    6 ++
 museum/backend/templates/wagtailadmin/admin_base.html   |    8 ++
 museum/backend/templates/wagtailadmin/base.html         |    6 ++
 museum/base/views.py                                    |    3 +
 22 files changed, 176 insertions(+), 0 deletions(-)

diff --git a/museum/backend/__init__.py b/museum/backend/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/museum/backend/__init__.py
diff --git a/museum/backend/admin.py b/museum/backend/admin.py
new file mode 100644
index 0000000..8c38f3f
--- /dev/null
+++ b/museum/backend/admin.py
@@ -0,0 +1,3 @@
+from django.contrib import admin
+
+# Register your models here.
diff --git a/museum/backend/apps.py b/museum/backend/apps.py
new file mode 100644
index 0000000..4439240
--- /dev/null
+++ b/museum/backend/apps.py
@@ -0,0 +1,6 @@
+from django.apps import AppConfig
+
+
+class BackendConfig(AppConfig):
+    default_auto_field = 'django.db.models.BigAutoField'
+    name = 'museum.backend'
diff --git a/museum/backend/migrations/__init__.py b/museum/backend/migrations/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/museum/backend/migrations/__init__.py
diff --git a/museum/backend/models.py b/museum/backend/models.py
new file mode 100644
index 0000000..3cf3cf5
--- /dev/null
+++ b/museum/backend/models.py
@@ -0,0 +1,51 @@
+from django.db import models
+from wagtail.admin.panels import FieldPanel
+from wagtail.images.edit_handlers import ImageChooserPanel
+
+
+class Book(models.Model):
+    title = models.CharField(max_length=255)
+    author = models.CharField(max_length=255)
+    cover_photo = models.ForeignKey(
+        'wagtailimages.Image',
+        on_delete=models.CASCADE,
+        related_name='+'
+    )
+
+    panels = [
+        FieldPanel('title'),
+        FieldPanel('author'),
+        ImageChooserPanel('cover_photo')
+    ]
+
+
+class Genre(models.Model):
+    title = models.CharField(max_length=255)
+    author = models.CharField(max_length=255)
+    cover_photo = models.ForeignKey(
+        'wagtailimages.Image',
+        on_delete=models.CASCADE,
+        related_name='+'
+    )
+
+    panels = [
+        FieldPanel('title'),
+        FieldPanel('author'),
+        ImageChooserPanel('cover_photo')
+    ]
+
+
+class Author(models.Model):
+    title = models.CharField(max_length=255)
+    author = models.CharField(max_length=255)
+    cover_photo = models.ForeignKey(
+        'wagtailimages.Image',
+        on_delete=models.CASCADE,
+        related_name='+'
+    )
+
+    panels = [
+        FieldPanel('title'),
+        FieldPanel('author'),
+        ImageChooserPanel('cover_photo')
+    ]
diff --git a/museum/backend/templates/wagtailadmin/404.html b/museum/backend/templates/wagtailadmin/404.html
new file mode 100644
index 0000000..b61aa8e
--- /dev/null
+++ b/museum/backend/templates/wagtailadmin/404.html
@@ -0,0 +1,6 @@
+{% extends "wagtailadmin/base.html" %}
+{% load static %}
+
+{% block branding_logo %}
+{#    <img src="{% static 'images/custom-logo.svg' %}" alt="Custom Project" width="80" />#}
+{% endblock %}
\ No newline at end of file
diff --git a/museum/backend/templates/wagtailadmin/admin_base.html b/museum/backend/templates/wagtailadmin/admin_base.html
new file mode 100644
index 0000000..512c8ef
--- /dev/null
+++ b/museum/backend/templates/wagtailadmin/admin_base.html
@@ -0,0 +1,8 @@
+{% extends "wagtailadmin/admin_base.html" %}
+{% load static %}
+
+{% block branding_favicon %}
+{#    <link rel="shortcut icon" href="{% static 'images/favicon.ico' %}" />#}
+{% endblock %}
+
+{% block branding_title %}museum{% endblock %}
\ No newline at end of file
diff --git a/museum/backend/templates/wagtailadmin/base.html b/museum/backend/templates/wagtailadmin/base.html
new file mode 100644
index 0000000..4f82846
--- /dev/null
+++ b/museum/backend/templates/wagtailadmin/base.html
@@ -0,0 +1,6 @@
+{% extends "wagtailadmin/base.html" %}
+{% load static %}
+
+{#{% block branding_logo %}#}
+{#    <img src="{% static 'images/custom-logo.svg' %}" alt="Custom Project" width="80" />#}
+{#{% endblock %}#}
\ No newline at end of file
diff --git a/museum/backend/templates/wagtailadmin/home.html b/museum/backend/templates/wagtailadmin/home.html
new file mode 100644
index 0000000..55438a9
--- /dev/null
+++ b/museum/backend/templates/wagtailadmin/home.html
@@ -0,0 +1,3 @@
+{% extends "wagtailadmin/home.html" %}
+
+{% block branding_welcome %} 你好{% endblock %}
\ No newline at end of file
diff --git a/museum/backend/templates/wagtailadmin/login.html b/museum/backend/templates/wagtailadmin/login.html
new file mode 100644
index 0000000..2a7c803
--- /dev/null
+++ b/museum/backend/templates/wagtailadmin/login.html
@@ -0,0 +1,3 @@
+{% extends "wagtailadmin/login.html" %}
+
+{% block branding_login %}对方的 {% endblock %}
\ No newline at end of file
diff --git a/museum/backend/templates/wagtailadmin/userbar/base.html b/museum/backend/templates/wagtailadmin/userbar/base.html
new file mode 100644
index 0000000..4f82846
--- /dev/null
+++ b/museum/backend/templates/wagtailadmin/userbar/base.html
@@ -0,0 +1,6 @@
+{% extends "wagtailadmin/base.html" %}
+{% load static %}
+
+{#{% block branding_logo %}#}
+{#    <img src="{% static 'images/custom-logo.svg' %}" alt="Custom Project" width="80" />#}
+{#{% endblock %}#}
\ No newline at end of file
diff --git a/museum/backend/tests.py b/museum/backend/tests.py
new file mode 100644
index 0000000..7ce503c
--- /dev/null
+++ b/museum/backend/tests.py
@@ -0,0 +1,3 @@
+from django.test import TestCase
+
+# Create your tests here.
diff --git a/museum/backend/views.py b/museum/backend/views.py
new file mode 100644
index 0000000..91ea44a
--- /dev/null
+++ b/museum/backend/views.py
@@ -0,0 +1,3 @@
+from django.shortcuts import render
+
+# Create your views here.
diff --git a/museum/backend/wagtail_hooks.py b/museum/backend/wagtail_hooks.py
new file mode 100644
index 0000000..49297b6
--- /dev/null
+++ b/museum/backend/wagtail_hooks.py
@@ -0,0 +1,58 @@
+from wagtail.contrib.modeladmin.options import (
+    ModelAdmin, modeladmin_register, ModelAdminGroup)
+from wagtail.core import hooks
+
+from .models import Book, Author, Genre
+
+
+@hooks.register('construct_main_menu')
+def hide_images_menu_item(request, menu_items):
+    menu_items[:] = [item for item in menu_items if item.name != 'help']
+
+
+# @hooks.register('construct_settings_menu')
+# def hide_user_menu_item(request, menu_items):
+#     menu_items[:] = [item for item in menu_items if item.name != 'user']
+
+
+class BookAdmin(ModelAdmin):
+    model = Book
+    menu_label = 'Book'  # ditch this to use verbose_name_plural from model
+    menu_icon = 'pilcrow'  # change as required
+    # menu_order = 3000  # will put in 3rd place (000 being 1st, 100 2nd)
+    # add_to_settings_menu = True  # or True to add your model to the Settings sub-menu
+    # exclude_from_explorer = True  # or True to exclude pages of this type from Wagtail's explorer view
+    list_display = ('title', 'author', 'cover_photo')
+    list_filter = ('author',)
+    search_fields = ('title', 'author')
+
+
+class AuthorAdmin(ModelAdmin):
+    model = Author
+    menu_label = 'Author'  # ditch this to use verbose_name_plural from model
+    menu_icon = 'user'  # change as required
+    list_display = ('first_name', 'last_name')
+    list_filter = ('first_name', 'last_name')
+    search_fields = ('first_name', 'last_name')
+
+
+class GenreAdmin(ModelAdmin):
+    model = Genre
+    menu_label = 'Genre'  # ditch this to use verbose_name_plural from model
+    menu_icon = 'group'  # change as required
+    list_display = ('name',)
+    list_filter = ('name',)
+    search_fields = ('name',)
+
+
+class LibraryGroup(ModelAdminGroup):
+    menu_label = 'Library'
+    menu_icon = 'folder-open-inverse'  # change as required
+    menu_order = 2000  # will put in 3rd place (000 being 1st, 100 2nd)
+    items = (BookAdmin, AuthorAdmin, GenreAdmin)
+
+# Now you just need to register your customised ModelAdmin class with Wagtail
+# modeladmin_register(LibraryGroup)
+# modeladmin_register(BookAdmin)
+# modeladmin_register(AuthorAdmin)
+# modeladmin_register(GenreAdmin)
diff --git a/museum/base/__init__.py b/museum/base/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/museum/base/__init__.py
diff --git a/museum/base/admin.py b/museum/base/admin.py
new file mode 100644
index 0000000..8c38f3f
--- /dev/null
+++ b/museum/base/admin.py
@@ -0,0 +1,3 @@
+from django.contrib import admin
+
+# Register your models here.
diff --git a/museum/base/apps.py b/museum/base/apps.py
new file mode 100644
index 0000000..8982e25
--- /dev/null
+++ b/museum/base/apps.py
@@ -0,0 +1,6 @@
+from django.apps import AppConfig
+
+
+class BaseConfig(AppConfig):
+    default_auto_field = 'django.db.models.BigAutoField'
+    name = 'museum.base'
diff --git a/museum/base/migrations/__init__.py b/museum/base/migrations/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/museum/base/migrations/__init__.py
diff --git a/museum/base/models.py b/museum/base/models.py
new file mode 100644
index 0000000..71a8362
--- /dev/null
+++ b/museum/base/models.py
@@ -0,0 +1,3 @@
+from django.db import models
+
+# Create your models here.
diff --git a/museum/base/tests.py b/museum/base/tests.py
new file mode 100644
index 0000000..7ce503c
--- /dev/null
+++ b/museum/base/tests.py
@@ -0,0 +1,3 @@
+from django.test import TestCase
+
+# Create your tests here.
diff --git a/museum/base/views.py b/museum/base/views.py
new file mode 100644
index 0000000..91ea44a
--- /dev/null
+++ b/museum/base/views.py
@@ -0,0 +1,3 @@
+from django.shortcuts import render
+
+# Create your views here.
diff --git a/museum/settings/base.py b/museum/settings/base.py
index c4cc39d..84dad47 100644
--- a/museum/settings/base.py
+++ b/museum/settings/base.py
@@ -31,6 +31,8 @@
     "museum.exhibition",
     "museum.education",
     "museum.information",
+    "museum.backend",
+    "museum.base",
     "wagtail.contrib.forms",
     "wagtail.contrib.redirects",
     "wagtail.embeds",

--
Gitblit v1.9.3