主な組織は、権利管理モジュール、スタッフの階層である、それはように、企業の組織構造、部門、チーム、であってもよいです。
達成する1つの新たな組織構造関数
1.1組織構造のテンプレートページ
組織構造テンプレートページ、ページは、ユーザーがアクセスしたときに、検索操作を、追加、変更、削除するために組織構造、組織構造を管理することです。
1、関連するすべてのテンプレート組織構造を格納するために使用される新しいフォルダsandboxMP /テンプレート/システム/構造
2を、作成したディレクトリ構造へのindex.html sandboxMP /テンプレート/コピー、名前の変更structure.html
3を、開いているだけのコピーstructure.htmlファイル、コード文字の内容を追加します。
{% block content %} <!-- Main content --> <section class="content"> 组织架构页:文字部分是新增内容,这里是组织架构的基础页面,有关组织架构的操作查询都是在这里完成的。 </section> <!-- /.content --> {% endblock %}
1.2組織ビューの基礎
図1に示すように、新しい文書sandboxMP /アプリケーション/システム/ views_structure.py、組織構造に関連するすべての操作はでviews_structure.pyに定義されたビュー。
2.作成したばかりの基本ビューviews_structure.pyファイル内の組織構造を定義します。
from django.views.generic.base import TemplateView
from .mixin import LoginRequiredMixin
class StructureView(LoginRequiredMixin, TemplateView): template_name = 'system/structure/structure.html'
1.3組織構造のアクセスURL
sandboxMP /アプリケーション/システム/ urls.pyを修正し、次の要素を追加します。
from . import views_structure
app_name = 'system'
urlpatterns = [
'''原有内容省略' path('basic/structure/', views_structure.StructureView.as_view(), name='basic-structure'), ]
プロジェクトを実行し、ページの組織構造にアクセスすることができますhttp://127.0.0.1:8000/system/basic/structure/
2組織構造を達成するための機能を追加
ビュー2.1組織構造を追加します。
ページがデータベース内に受信され、格納されたデータを追加するために送信され、レンダリングされたページを追加:機能ビューを追加すると、実装されている
以下の追加、1 sandboxMP /アプリケーション/システム/ forms.py修飾します:
from .models import Structure
class StructureForm(forms.ModelForm): class Meta: model = Structure fields = ['type', 'name', 'parent']
2、以下を追加し、sandboxMP /アプリケーション/システム/ views_structure.pyを変更します。
import json
from django.views.generic.base import View
from django.shortcuts import render from django.shortcuts import HttpResponse from .models import Structure from .forms import StructureForm class StructureCreateView(LoginRequiredMixin, View): def get(self, request): ret = dict(structure_all=Structure.objects.all()) return render(request, 'system/structure/structure_create.html', ret) def post(self, request): res = dict(result=False) structure = Structure() structure_form = StructureForm(request.POST, instance=structure) if structure_form.is_valid(): structure_form.save() res['result'] = True return HttpResponse(json.dumps(res), content_type='application/json')
2.2 URLの機能の設定を追加するための組織構造:
sandboxMP /アプリケーション/システム/ urls.pyを修正し、中にurlpatternsに新しいコンテンツを追加します。
urlpatterns = [
'''原有内容省略'''
path('basic/structure/create/', views_structure.StructureCreateView.as_view(), name='basic-structure-create'),
]
2.3の追加ページテンプレートの組織構造
ページの組織を追加し、ポップ・ページで、sandboxMP /テンプレート/ base_layer.html、結果ページを継承しました。
1、sandboxMP /テンプレート/システムにおける新たな組織構造/構造の内容は、テンプレートの追加:structure_create.html
2を、structure_create.html元のコンテンツを削除し、以下の内容を追加します。
{% extends 'base-layer.html' %} {% load staticfiles %} {% block css %} <link rel="stylesheet" href="{% static 'js/plugins/layer/skin/layer.css' %}"> {% endblock %} {% block main %} <div class="box box-danger"> <form class="form-horizontal" id="addForm" method="post"> {% csrf_token %} <div class="box-body"> <fieldset> <legend> <h4>组织架构信息</h4> </legend> <div class="form-group has-feedback"> <label class="col-sm-2 control-label">名称</label> <div class="col-sm-3"> <input class="form-control" name="name" type="text" /> </div> <label class="col-sm-2 control-label">类别</label> <div class="col-sm-3"> <select class="form-control" name="type"> <option value="unit">单位</option> <option value="department">部门</option> </select> </div> </div> <div class="form-group has-feedback"> <label class="col-sm-2 control-label">所属</label> <div class="col-sm-3"> <select class="form-control" name="parent"> <option></option> {% for stru in structure_all %} <option value={{ stru.id }}> {{ stru.name }} </option> {% endfor %} </select> </div> </div> </fieldset> </div> <div class="box-footer "> <div class="row span7 text-center "> <button type="button" id="btnCancel" class="btn btn-default margin-right ">重置</button> <button type="button" id="btnSave" class="btn btn-info margin-right ">保存</button> </div> </div> </form> </div> {% endblock %} {% block javascripts %} <script type="text/javascript"> $("#btnSave").click(function () { var data = $("#addForm").serialize(); $.ajax({ type: $("#addForm").attr('method'), url: "{% url 'system:basic-structure-create' %}", data: data, cache: false, success: function (msg) { if (msg.result) { layer.alert('