提交 57a31546 编写于 作者: N newpanjing

add readme.md

上级 90f49c0f
......@@ -4,13 +4,15 @@ django simpleui demo.
## setup
```
#runserver
python manage.py runserver 8000
pip install django django-simpleui
#open browser
http://127.0.0.1:8000/admin
python manage.py runserver 8000
#username and password
simpleui 123456
```
#open browser
http://127.0.0.1:8000/admin
```
\ No newline at end of file
username and password:
>simpleui 123456
\ No newline at end of file
无法预览此类型文件
default_app_config = 'demo.apps.DemoConfig'
from django.contrib import admin
from .models import *
# Register your models here.
@admin.register(Department)
class DepartmentAdmin(admin.ModelAdmin):
# 要显示的字段
list_display = ('id', 'name', 'create_time')
# 需要搜索的字段
search_fields = ('name',)
# 分页显示,一页的数量
list_per_page = 10
actions_on_top = True
@admin.register(Employe)
class EmployeAdmin(admin.ModelAdmin):
list_display = ('id', 'name', 'gender', 'idCard', 'phone', 'birthday', 'department', 'enable', 'create_time')
search_fields = ('name', 'enable')
list_per_page = 10
list_filter = ('department', 'create_time', 'birthday', 'time', 'enable', 'gender')
list_display_links = ('name', 'idCard')
list_editable = ('department', 'phone', 'birthday', 'enable', 'gender')
date_hierarchy = 'create_time'
# 增加自定义按钮
actions = ['make_copy']
def make_copy(self, request, queryset):
ids = request.POST.getlist('_selected_action')
for id in ids:
employe = Employe.objects.get(id=id)
Employe.objects.create(
name=employe.name,
idCard=employe.idCard,
phone=employe.phone,
birthday=employe.birthday,
department_id=employe.department_id
)
make_copy.short_description = '复制员工'
......@@ -3,3 +3,4 @@ from django.apps import AppConfig
class DemoConfig(AppConfig):
name = 'demo'
verbose_name = '综合管理'
from django.db import models
# Create your models here.
class Department(models.Model):
name = models.CharField(max_length=128, verbose_name='部门名', help_text='一个部门的名字应该唯一', unique=True, db_index=True)
create_time = models.DateTimeField(verbose_name='创建时间', auto_now=True)
class Meta:
verbose_name = "部门"
verbose_name_plural = "部门管理"
def __str__(self):
return self.name
class Employe(models.Model):
name = models.CharField(max_length=128, verbose_name='名称', help_text='员工的名字', null=False, blank=False,
db_index=True)
gender_choices = (
(0, '未知'),
(1, '男'),
(2, '女'),
)
gender = models.IntegerField(choices=gender_choices, verbose_name='性别', default=0)
idCard = models.CharField(max_length=18, verbose_name='身份证号', help_text='18位的身份证号码', blank=True, null=True)
phone = models.CharField(max_length=11, verbose_name='手机号')
birthday = models.DateField(verbose_name='生日')
time = models.TimeField(verbose_name='时间', auto_now=True)
department = models.ForeignKey(Department, on_delete=models.SET_NULL, blank=False, null=True, verbose_name='部门',
db_index=True)
enable = models.BooleanField(verbose_name='状态', default=True)
create_time = models.DateTimeField(verbose_name='创建时间', auto_now=True)
update_time = models.DateTimeField(verbose_name='更新时间', auto_now=True)
class Meta:
verbose_name = "员工"
verbose_name_plural = "员工管理"
def __str__(self):
return self.name
......@@ -15,7 +15,6 @@ import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
......@@ -25,8 +24,7 @@ SECRET_KEY = '&%up9@!s_$$4(qurnori=vit2#kg!bzs$_+m64^j$2-vzibx&p'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['*',]
ALLOWED_HOSTS = ['*', ]
# Application definition
......@@ -38,7 +36,10 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'demo.apps.DemoConfig',
# 'demo.apps.DemoConfig',
# 注册自己的app
'demo',
'finance',
]
MIDDLEWARE = [
......@@ -56,8 +57,7 @@ ROOT_URLCONF = 'simpleui_demo.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')]
,
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
......@@ -72,7 +72,6 @@ TEMPLATES = [
WSGI_APPLICATION = 'simpleui_demo.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
......@@ -83,7 +82,6 @@ DATABASES = {
}
}
# Password validation
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
......@@ -102,11 +100,12 @@ AUTH_PASSWORD_VALIDATORS = [
},
]
# Internationalization
# https://docs.djangoproject.com/en/2.1/topics/i18n/
LANGUAGE_CODE = 'zh-hans'
# LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Asia/Shanghai'
......@@ -116,8 +115,21 @@ USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/
STATIC_URL = '/static/'
# STATICFILES_DIRS = [
# os.path.join(BASE_DIR, "static"),
# ]
STATIC_ROOT = os.path.join(BASE_DIR, "static")
# simpleui 设置
# 首页配置
# SIMPLEUI_HOME_PAGE = 'https://www.baidu.com'
# 首页标题
# SIMPLEUI_HOME_TITLE = '百度一下你就知道'
# 首页图标,支持element-ui的图片和fontawesome的图标
# SIMPLEUI_HOME_ICON = 'el-icon-date'
......@@ -16,6 +16,9 @@ Including another URLconf
from django.contrib import admin
from django.urls import path
admin.site.site_title = '管理后台'
admin.site.site_header = '员工管理后台'
urlpatterns = [
path('admin/', admin.site.urls),
]
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册