mirror of
https://github.com/RobbieHan/sandboxMP.git
synced 2026-04-05 03:28:40 +08:00
structure create
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
apps/system/__pycache__/views_structure.cpython-36.pyc
Normal file
BIN
apps/system/__pycache__/views_structure.cpython-36.pyc
Normal file
Binary file not shown.
Binary file not shown.
@@ -3,8 +3,15 @@
|
||||
# @File : forms.py
|
||||
|
||||
from django import forms
|
||||
from .models import Structure
|
||||
|
||||
|
||||
class LoginForm(forms.Form):
|
||||
username = forms.CharField(required=True, error_messages={"requeired": "请填写用户名"})
|
||||
password = forms.CharField(required=True, error_messages={"requeired": "请填写密码"})
|
||||
password = forms.CharField(required=True, error_messages={"requeired": "请填写密码"})
|
||||
|
||||
|
||||
class StructureForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Structure
|
||||
fields = ['type', 'name', 'parent']
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
from django.urls import path
|
||||
|
||||
from .views import SystemView
|
||||
from . import views_structure
|
||||
|
||||
app_name = 'system'
|
||||
|
||||
urlpatterns = [
|
||||
path('', SystemView.as_view(), name='login'),
|
||||
path('basic/structure/', views_structure.StructureView.as_view(), name='basic-structure'),
|
||||
path('basic/structure/create/', views_structure.StructureCreateView.as_view(), name='basic-structure-create'),
|
||||
]
|
||||
|
||||
|
||||
35
apps/system/views_structure.py
Normal file
35
apps/system/views_structure.py
Normal file
@@ -0,0 +1,35 @@
|
||||
# @Time : 2018/10/18 23:04
|
||||
# @Author : RobbieHan
|
||||
# @File : views_structure.py
|
||||
|
||||
import json
|
||||
|
||||
from django.views.generic.base import TemplateView
|
||||
from django.views.generic.base import View
|
||||
from django.shortcuts import render
|
||||
from django.shortcuts import HttpResponse
|
||||
|
||||
from .mixin import LoginRequiredMixin
|
||||
from .models import Structure
|
||||
from .forms import StructureForm
|
||||
|
||||
|
||||
class StructureView(LoginRequiredMixin, TemplateView):
|
||||
|
||||
template_name = 'system/structure/structure.html'
|
||||
|
||||
|
||||
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')
|
||||
Reference in New Issue
Block a user