import copy
import json
import operator
import re
from collections import OrderedDict
from functools import partial, reduce, update_wrapper
from urllib.parse import quote as urlquote
from django import forms
from django.conf import settings
from django.contrib import messages
from django.contrib.admin import helpers, widgets
from django.contrib.admin.checks import (
BaseModelAdminChecks, InlineModelAdminChecks, ModelAdminChecks,
)
from django.contrib.admin.exceptions import DisallowedModelAdminToField
from django.contrib.admin.templatetags.admin_urls import add_preserved_filters
from django.contrib.admin.utils import (
NestedObjects, construct_change_message, flatten_fieldsets,
get_deleted_objects, lookup_needs_distinct, model_format_dict,
model_ngettext, quote, unquote,
)
from django.contrib.admin.views.autocomplete import AutocompleteJsonView
from django.contrib.admin.widgets import (
AutocompleteSelect, AutocompleteSelectMultiple,
)
from django.contrib.auth import get_permission_codename
from django.core.exceptions import (
FieldDoesNotExist, FieldError, PermissionDenied, ValidationError,
)
from django.core.paginator import Paginator
from django.db import models, router, transaction
from django.db.models.constants import LOOKUP_SEP
from django.db.models.fields import BLANK_CHOICE_DASH
from django.forms.formsets import DELETION_FIELD_NAME, all_valid
from django.forms.models import (
BaseInlineFormSet, inlineformset_factory, modelform_defines_fields,
modelform_factory, modelformset_factory,
)
from django.forms.widgets import CheckboxSelectMultiple, SelectMultiple
from django.http import HttpResponseRedirect
from django.http.response import HttpResponseBase
from django.template.response import SimpleTemplateResponse, TemplateResponse
from django.urls import reverse
from django.utils.decorators import method_decorator
from django.utils.html import format_html
from django.utils.http import urlencode
from django.utils.inspect import get_func_args
from django.utils.safestring import mark_safe
from django.utils.text import capfirst, format_lazy, get_text_list
from django.utils.translation import gettext as _, ngettext
from django.views.decorators.csrf import csrf_protect
from django.views.generic import RedirectView
IS_POPUP_VAR = '_popup'
TO_FIELD_VAR = '_to_field'
HORIZONTAL, VERTICAL = 1, 2
def get_content_type_for_model(obj):
# Since this module gets imported in the application's root package,
# it cannot import models from other applications at the module level.
from django.contrib.contenttypes.models import ContentType
return ContentType.objects.get_for_model(obj, for_concrete_model=False)
def get_ul_class(radio_style):
return 'radiolist' if radio_style == VERTICAL else 'radiolist inline'
class IncorrectLookupParameters(Exception):
pass
# Defaults for formfield_overrides. ModelAdmin subclasses can change this
# by adding to ModelAdmin.formfield_overrides.
FORMFIELD_FOR_DBFIELD_DEFAULTS = {
models.DateTimeField: {
'form_class': forms.SplitDateTimeField,
'widget': widgets.AdminSplitDateTime
},
models.DateField: {'widget': widgets.AdminDateWidget},
models.TimeField: {'widget': widgets.AdminTimeWidget},
models.TextField: {'widget': widgets.AdminTextareaWidget},
models.URLField: {'widget': widgets.AdminURLFieldWidget},
models.IntegerField: {'widget': widgets.AdminIntegerFieldWidget},
models.BigIntegerField: {'widget': widgets.AdminBigIntegerFieldWidget},
models.CharField: {'widget': widgets.AdminTextInputWidget},
models.ImageField: {'widget': widgets.AdminFileWidget},
models.FileField: {'widget': widgets.AdminFileWidget},
models.EmailField: {'widget': widgets.AdminEmailInputWidget},
}
csrf_protect_m = method_decorator(csrf_protect)
class BaseModelAdmin(metaclass=forms.MediaDefiningClass):
"""Functionality common to both ModelAdmin and InlineAdmin."""
autocomplete_fields = ()
raw_id_fields = ()
fields = None
exclude = None
fieldsets = None
form = forms.ModelForm
filter_vertical = ()
filter_horizontal = ()
radio_fields = {}
prepopulated_fields = {}
formfield_overrides = {}
readonly_fields = ()
ordering = None
sortable_by = None
view_on_site = True
show_full_result_count = True
checks_class = BaseModelAdminChecks
def check(self, **kwargs):
return self.checks_class().check(self, **kwargs)
def __init__(self):
# Merge FORMFIELD_FOR_DBFIELD_DEFAULTS with the formfield_overrides
# rather than simply overwriting.
overrides = copy.deepcopy(FORMFIELD_FOR_DBFIELD_DEFAULTS)
for k, v in self.formfield_overrides.items():
overrides.setdefault(k, {}).update(v)
self.formfield_overrides = overrides
def formfield_for_dbfield(self, db_field, request, **kwargs):
"""
Hook for specifying the form Field instance for a given database Field
instance.
If kwargs are given, they're passed to the form Field's constructor.
"""
# If the field specifies choices, we don't need to look for special
# admin widgets - we just need to use a select widget of some kind.
if db_field.choices:
return self.formfield_for_choice_field(db_field, request, **kwargs)
# ForeignKey or ManyToManyFields
if isinstance(db_field, (models.ForeignKey, models.ManyToManyField)):
# Combine the field kwargs with any options for formfield_overrides.
# Make sure the passed in **kwargs override anything in
# formfield_overrides because **kwargs is more specific, and should
# always win.
if db_field.__class__ in self.formfield_overrides:
kwargs = {**self.formfield_overrides[db_field.__class__], **kwargs}
# Get the correct formfield.
if isinstance(db_field, models.ForeignKey):
formfield = self.formfield_for_foreignkey(db_field, request, **kwargs)
elif isinstance(db_field, models.ManyToManyField):
formfield = self.formfield_for_manytomany(db_field, request, **kwargs)
# For non-raw_id fields, wrap the widget with a wrapper that adds
# extra HTML -- the "add other" interface -- to the end of the
# rendered output. formfield can be None if it came from a
# OneToOneField with parent_link=True or a M2M intermediary.
if formfield and db_field.name not in self.raw_id_fields:
related_modeladmin = self.admin_site._registry.get(db_field.remote_field.model)
wrapper_kwargs = {}
if related_modeladmin:
wrapper_kwargs.update(
can_add_related=related_modeladmin.has_add_permission(request),
can_change_related=related_modeladmin.has_change_permission(request),
can_delete_related=related_modeladmin.has_delete_permission(request),
can_view_related=related_modeladmin.has_view_permission(request),
)
formfield.widget = widgets.RelatedFieldWidgetWrapper(
formfield.widget, db_field.remote_field, self.admin_site, **wrapper_kwargs
)
return formfield
# If we've got overrides for the formfield defined, use 'em. **kwargs
# passed to formfield_for_dbfield override the defaults.
for klass in db_field.__class__.mro():
if klass in self.formfield_overrides:
kwargs = {**copy.deepcopy(self.formfield_overrides[klass]), **kwargs}
return db_field.formfield(**kwargs)
# For any other type of field, just call its formfield() method.
return db_field.formfield(**kwargs)
def formfield_for_choice_field(self, db_field, request, **kwargs):
"""
Get a
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
全国计算机等级考试刷题系统-NCER.zip (2000个子文件)
style.css 128KB
bootstrap.css 123KB
bootstrap.min.css 100KB
editor_ie8.css 48KB
editor_iequirks.css 47KB
editor_ie.css 47KB
editor_gecko.css 46KB
editor.css 46KB
editor_ie7.css 45KB
editor_iequirks.css 44KB
editor_ie8.css 43KB
editor_ie.css 43KB
editor_gecko.css 42KB
editor.css 42KB
style.css 38KB
font-awesome.css 21KB
bootstrap-theme.css 19KB
select2.css 19KB
responsive.css 18KB
responsive.css 18KB
font-awesome.min.css 17KB
bootstrap-theme.min.css 17KB
select2.css 17KB
select2.css 17KB
base.css 16KB
selectize.bootstrap2.css 15KB
select2.min.css 15KB
select2.min.css 15KB
dialog_ie8.css 15KB
dialog_ie7.css 15KB
dialog_ie8.css 14KB
dialog_iequirks.css 14KB
dialog_ie.css 14KB
dialog_iequirks.css 14KB
dialog_ie.css 14KB
dialog.css 13KB
dialog.css 13KB
selectize.default.css 11KB
selectize.legacy.css 11KB
selectize.bootstrap3.css 10KB
widgets.css 10KB
datepicker.css 10KB
forms.css 8KB
forms.css 8KB
autocomplete.css 8KB
autocomplete.css 8KB
selectize.css 8KB
xadmin.main.css 8KB
changelists.css 6KB
changelists.css 6KB
xadmin.responsive.css 4KB
bootstrap-modal.css 4KB
rtl.css 4KB
xadmin.form.css 4KB
rtl.css 4KB
bootstrap-clockpicker.css 4KB
galleriffic-5.css 3KB
galleriffic-4.css 3KB
galleriffic-1.css 3KB
bootstrap-image-gallery.css 3KB
galleriffic-3.css 3KB
galleriffic-2.css 3KB
bootstrap-clockpicker.min.css 3KB
contents.css 3KB
default.css 3KB
bootstrap-timepicker.css 3KB
railscasts.css 3KB
bootstrap-image-gallery.min.css 2KB
yui.css 2KB
arta.css 2KB
monokai_sublime.css 2KB
obsidian.css 2KB
xcode.css 2KB
bootstrap-timepicker.min.css 2KB
sunburst.css 2KB
xadmin.widget.select-transfer.css 2KB
googlecode.css 2KB
monokai.css 2KB
school_book.css 2KB
magula.css 2KB
far.css 2KB
zenburn.css 2KB
responsive_rtl.css 2KB
docco.css 2KB
brown_paper.css 2KB
bootstrap-xadmin.css 2KB
atelier-lakeside.light.css 2KB
dark.css 2KB
responsive_rtl.css 2KB
atelier-lakeside.dark.css 2KB
idea.css 2KB
atelier-seaside.light.css 2KB
atelier-seaside.dark.css 2KB
atelier-forest.light.css 2KB
jush.css 2KB
atelier-forest.dark.css 2KB
atelier-heath.light.css 2KB
atelier-heath.dark.css 2KB
atelier-dune.light.css 2KB
atelier-dune.dark.css 2KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
武昌库里写JAVA
- 粉丝: 6668
- 资源: 3166
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 点云数据处理与开发基础教程
- (源码)基于 JavaWeb 的超市收银系统.zip
- (源码)基于Vue和Cordova的移动端在线选座购票系统.zip
- (源码)基于C++的simpleDB数据库管理系统.zip
- (源码)基于Arduino的RTOSMMESGU实时操作系统项目.zip
- (源码)基于STM32和TensorFlow Lite框架的微语音识别系统.zip
- (源码)基于C#的支付系统集成SDK.zip
- (源码)基于Spring Cloud和Spring Boot的微服务架构管理系统.zip
- (源码)基于物联网的自动化开门控制系统 iotsaDoorOpener.zip
- (源码)基于ROS的Buddy Robot舞蹈控制系统.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功