Skip to content

Django2 #593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 47 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
fc8155b
适配django 2.0正式版
wgbbiao Dec 5, 2017
0fe415f
修改文档
wgbbiao Dec 5, 2017
bbaebd6
修改列表编辑插件不能使用的问题,暂时解决了,可能会有其它的问题,欢迎测试.
wgbbiao Dec 6, 2017
8263c23
适配python3
wgbbiao Dec 7, 2017
b046c86
增加检查 form media的判断
wgbbiao Dec 7, 2017
d3bcb12
修改不能使用只读字段的功能
wgbbiao Dec 8, 2017
b69e1aa
增加安装分支的说明
wgbbiao Dec 11, 2017
a0f6173
修改readme 格式
wgbbiao Dec 11, 2017
1f4a3e1
兼容django 2.0
wgbbiao Dec 12, 2017
ce7df0d
Update filters.py
ly0 Dec 12, 2017
a975de0
Merge pull request #476 from ly0/patch-2
wgbbiao Dec 14, 2017
749ff5b
删除手机插件
wgbbiao Dec 25, 2017
c53c33a
修复运行时缺少包的问题
hyzx86 Dec 31, 2017
b655aa7
Merge pull request #496 from hyzx86/patch-4
wgbbiao Jan 2, 2018
932e371
DeprecationWarning: inspect.getargspec() is deprecated, use inspect.s…
wgbbiao Jan 29, 2018
82a8a3b
Fix Django2.0 issue #449
YennyQ Apr 26, 2018
e95e6cb
Fix Django2.0 widgets.py AdminSplitDateTime IndexError
YennyQ Apr 26, 2018
9ca81ed
Merge pull request #570 from YennyQ/django2
wgbbiao May 7, 2018
9cbf87e
删除测试代码
wgbbiao May 7, 2018
031baee
Merge branch 'master' into django2
wgbbiao May 7, 2018
f2a3ae2
修改inline 点加号出现的问题
wgbbiao May 18, 2018
c2f0e8e
Update requirements.txt
xiaofeng283 Jun 17, 2018
21e6557
Merge pull request #587 from xiaofeng283-t/django2
wgbbiao Jun 19, 2018
694606d
django2.0适配版本的editable.py第59行,缺少Media的引用
wgbbiao Jun 19, 2018
66ebad6
Merge branch 'django2' of github.com:sshwsfc/xadmin into django2
wgbbiao Jun 19, 2018
f1f07f0
修复获取单个记录时引发select all的问题
hongweipeng Jun 25, 2018
4ed71ef
Merge pull request #589 from hongweipeng/patch-1
wgbbiao Jun 25, 2018
dbd5d4c
修复列表页重复查询的问题
hongweipeng Jun 25, 2018
475289b
Merge pull request #590 from hongweipeng/patch-1
wgbbiao Jun 27, 2018
1e3f7b1
修复meta.get_all_field_names不存在问题
hongweipeng Jun 27, 2018
b03dade
Merge pull request #591 from hongweipeng/patch-1
wgbbiao Jun 29, 2018
a3b200c
修改tab 不显示的问题
wgbbiao Aug 7, 2018
1276190
适配django 2.1
wgbbiao Aug 8, 2018
d7e283f
修改安装django2分支的命令
wgbbiao Aug 8, 2018
a9daa73
适配django 2.1 2.0 fixed : https://github.com/sshwsfc/xadmin/issues/612
wgbbiao Aug 15, 2018
9072fdd
fix images.py in django 2.1
njuFerret Aug 19, 2018
4f626bb
Merge pull request #614 from njuFerret/django2
wgbbiao Aug 19, 2018
0751cd9
兼容django 2.1版本,修改删除级联关系的记录时会抛出找不到 has_delete_permission 的问题
wgbbiao Aug 29, 2018
0b63e39
修改在详情页删除数据报的错误
wgbbiao Sep 17, 2018
5c0e836
左侧菜单内容过多时显示滚动条
hongweipeng Sep 20, 2018
0b214ac
Merge pull request #627 from hongweipeng/django2-sitemenu-scroll
wgbbiao Sep 25, 2018
992d780
fixed 有外键字段的,没有显示相关联字段详情的按钮 #629 https://github.com/sshwsfc/xadmin/is…
wgbbiao Sep 30, 2018
0aa9d2a
fix bug when using `get_deleted_objects` function
mymusise Oct 9, 2018
375db83
update version judgement
mymusise Oct 19, 2018
35a854c
修复django版本判断导致get_deleted_objects参数错误问题
hongweipeng Oct 30, 2018
33356ce
Merge pull request #638 from hongweipeng/fix-get_deleted_objects-djan…
wgbbiao Oct 31, 2018
47481fe
Merge pull request #633 from mymusise/django2
wgbbiao Oct 31, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ Install from github source for Django 2.0:

.. code:: bash

pip install git+git://github.com/sshwsfc/xadmin.git@django2
pip install https://codeload.github.com/sshwsfc/xadmin/zip/django2

Install Requires
----------------

- `django`_ >=1.9
- `django`_ >=2

- `django-crispy-forms`_ >=1.6.0 (For xadmin crispy forms)

Expand Down
9 changes: 6 additions & 3 deletions demo_app/app/adminx.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class IDCAdmin(object):

@xadmin.sites.register(Host)
class HostAdmin(object):

def open_web(self, instance):
return """<a href="http://%s" target="_blank">Open</a>""" % instance.ip

Expand All @@ -87,7 +88,7 @@ def open_web(self, instance):
raw_id_fields = ("idc",)
style_fields = {"system": "radio-inline"}

search_fields = ["name", "ip", "description"]
search_fields = ["name", "ip", "description", "idc__name"]
list_filter = [
"idc", "guarantee_date", "status", "brand", "model", "cpu", "core_num",
"hard_disk", "memory", (
Expand Down Expand Up @@ -164,6 +165,7 @@ class HostGroupAdmin(object):
list_display = ("name", "description")
list_display_links = ("name",)

list_filter = ["hosts"]
search_fields = ["name"]
style_fields = {"hosts": "checkbox-inline"}

Expand Down Expand Up @@ -200,6 +202,7 @@ class MaintainLogAdmin(object):

@xadmin.sites.register(AccessRecord)
class AccessRecordAdmin(object):

def avg_count(self, instance):
return int(instance.view_count / instance.user_count)

Expand All @@ -223,8 +226,8 @@ def avg_count(self, instance):
"option": {
"series": {"bars": {"align": "center", "barWidth": 0.8, 'show': True}},
"xaxis": {"aggregate": "sum", "mode": "categories"},
},
},
},
},
}

def _chart_month(self, obj):
Expand Down
7 changes: 4 additions & 3 deletions demo_app/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
('mix', u"Mix"),
)


@python_2_unicode_compatible
class IDC(models.Model):
name = models.CharField(max_length=64)
Expand All @@ -46,7 +47,7 @@ class Meta:

@python_2_unicode_compatible
class Host(models.Model):
idc = models.ForeignKey(IDC)
idc = models.ForeignKey(IDC, on_delete=models.CASCADE)
name = models.CharField(max_length=64)
nagios_name = models.CharField(u"Nagios Host ID", max_length=64, blank=True, null=True)
ip = models.GenericIPAddressField(blank=True, null=True)
Expand All @@ -72,7 +73,7 @@ class Host(models.Model):
service_type = models.CharField(max_length=32, choices=SERVICE_TYPES)
description = models.TextField()

administrator = models.ForeignKey(AUTH_USER_MODEL, verbose_name="Admin")
administrator = models.ForeignKey(AUTH_USER_MODEL, on_delete=models.CASCADE, verbose_name="Admin")

def __str__(self):
return self.name
Expand All @@ -84,7 +85,7 @@ class Meta:

@python_2_unicode_compatible
class MaintainLog(models.Model):
host = models.ForeignKey(Host)
host = models.ForeignKey(Host, on_delete=models.CASCADE)
maintain_type = models.CharField(max_length=32)
hard_type = models.CharField(max_length=16)
time = models.DateTimeField()
Expand Down
232 changes: 82 additions & 150 deletions demo_app/demo/settings.py
Original file line number Diff line number Diff line change
@@ -1,198 +1,130 @@
# Django settings for wictrl project.
"""
Django settings for demo_app project.

import sys
import os.path
from django.utils import six
Generated by 'django-admin startproject' using Django 2.0.

if six.PY2 and sys.getdefaultencoding()=='ascii':
import imp
imp.reload(sys)
sys.setdefaultencoding('utf-8')
For more information on this file, see
https://docs.djangoproject.com/en/2.0/topics/settings/

from django.utils.translation import ugettext_lazy as _
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.0/ref/settings/
"""

PROJECT_ROOT = os.path.join(
os.path.realpath(os.path.dirname(__file__)), os.pardir)
# PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
import os
from django.utils.translation import ugettext_lazy as _
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

DEBUG = True

ADMINS = (
# ('Your Name', '[email protected]'),
)
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/

MANAGERS = ADMINS

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': os.path.join(PROJECT_ROOT, 'data.db'), # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
# Hosts/domain names that are valid for this site; required if DEBUG is False
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
ALLOWED_HOSTS = ['*']

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# In a Windows environment this must be set to your system time zone.
TIME_ZONE = 'America/Chicago'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'l!fafmjcqyn+j+zz1@2@wt$o8w8k(_dhgub%41l#k3zi2m-b%m'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
LANGUAGES = (
('en', _('English')),
('zh-hans', _('Chinese')),
)

SITE_ID = 1
ALLOWED_HOSTS = []

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = True

# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = True

# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = ''
# Application definition

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = ''

# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = 'static/'

# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'

# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
'xadmin',
'crispy_forms',
'reversion',

# Make this unique, and don't share it with anybody.
SECRET_KEY = '5=!nss_+^nvyyc_j(tdcf!7(_una*3gtw+_8v5jaa=)j0g^d_2'
'app',
]

MIDDLEWARE_CLASSES = (
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.locale.LocaleMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'demo.urls'

# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'demo.wsgi.application'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(PROJECT_ROOT,"templates"),
],
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
'debug': DEBUG,
},
},
]

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
WSGI_APPLICATION = 'demo.wsgi.application'

'xadmin',
'crispy_forms',
'reversion',

'app',
)
# Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases

TEST_RUNNER = 'django.test.runner.DiscoverRunner'

# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error when DEBUG=False.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
},
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler'
},
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
# 'django.db.backends': {
# 'handlers': ['console'],
# 'level': 'DEBUG',
# }
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}


# Password validation
# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]


# Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/

STATIC_URL = '/static/'
6 changes: 3 additions & 3 deletions demo_app/demo/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from django.conf.urls import include, url
# from django.conf.urls import include, url
from django.urls import include, path

# Uncomment the next two lines to enable the admin:
import xadmin
Expand All @@ -12,6 +13,5 @@
from django.contrib import admin

urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^', include(xadmin.site.urls))
path(r'', xadmin.site.urls)
]
Loading