Skip to content

Commit

Permalink
添加django-suit作为admin后台ui
Browse files Browse the repository at this point in the history
  • Loading branch information
wuyue92tree committed Jul 1, 2018
1 parent 6a88318 commit 624e7bc
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 5 deletions.
6 changes: 3 additions & 3 deletions rest_backend/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
# Application definition

INSTALLED_APPS = [
'rest_backend.utils.suit.SuitConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
Expand Down Expand Up @@ -66,13 +67,12 @@
AUTH_USER_MODEL = 'accounts.User'

# session过期时间设置
SESSION_COOKIE_AGE = 60*30

SESSION_COOKIE_AGE = 60 * 30

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
Expand Down
5 changes: 3 additions & 2 deletions rest_backend/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@

urlpatterns = [
path('admin/', admin.site.urls),
path('', RedirectView.as_view(url='/api-docs')),
path('', include('rest_backend.libs.backend.urls'))
path('', RedirectView.as_view(url='/admin/')),
path('', include('rest_framework.urls', namespace='rest_framework')),
path('api/', include('rest_backend.libs.backend.urls', namespace='api'))
]

if settings.DEBUG:
Expand Down
32 changes: 32 additions & 0 deletions rest_backend/utils/suit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""
@author: wuyue
@contact: [email protected]
@software: PyCharm
@file: suit.py
@create at: 2018-04-29 11:58
这一行开始写关于本文件的说明与解释
"""

from django.contrib import admin
from suit.apps import DjangoSuitConfig
from suit.menu import ParentItem, ChildItem

admin.AdminSite.site_header = 'rest_backend后台管理'


class SuitConfig(DjangoSuitConfig):
layout = 'vertical'
menu = (
ParentItem('认证和授权', children=[
ChildItem(model='accounts.user'),
ChildItem(model='auth.group'),
], icon='fa fa-users'),
ParentItem('设置', children=[
# ChildItem('修改密码', url='admin:password_change'),
ChildItem('API接口文档', url='/api/docs', target_blank=True),

], align_right=True, icon='fa fa-cog'),
)
46 changes: 46 additions & 0 deletions templates/admin/base_site.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{% extends 'admin/base.html' %}
{% load suit_tags admin_static %}
{% block footer %}
{% if not is_popup %}
<div id="footer">
<footer class="footer">
<div class="container-fluid">
{% block footer_content %}
<div class="row">

<div class="col-xs-12 col-sm-6 text-sm-center footer-copyright">
{% block copyright %}
Copyright &copy;
<span class="hidden-md-down">2017-</span>{% now "Y" %}
<br>{{ site_header }} by <a target="_blank" href="http://wuyue92tree.antio.top/opensource/rest-backend.html">WUYUE</a>
{% endblock %}
</div>

</div>
{% endblock %}
</div>
</footer>
{% endif %}

<script src="{% static "suit/js/suit.js" %}"></script>
{% if cl.formset or action_form and 'toggle_changelist_top_actions'|suit_conf:request %}
<script type="text/javascript">
Suit.ListActionsToggle.init();
</script>
{% elif adminform %}
<script type="text/javascript">

Suit.$("#{{ opts.model_name }}_form").suitFormDebounce();

{% if 'form_submit_on_right'|suit_conf:request %}
Suit.FixedBar.init();
{% endif %}

{% if adminform.model_admin.suit_form_tabs %}
Suit.$(function () {
Suit.$('#suit_form_tabs').suitFormTabs();
});
{% endif %}
</script>
{% endif %}
{% endblock %}

0 comments on commit 624e7bc

Please sign in to comment.