本文整理汇总了Python中django.contrib.admin.sites.AdminSite.register方法的典型用法代码示例。如果您正苦于以下问题:Python AdminSite.register方法的具体用法?Python AdminSite.register怎么用?Python AdminSite.register使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.admin.sites.AdminSite
的用法示例。
在下文中一共展示了AdminSite.register方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestCflatpagesAdmin
# 需要导入模块: from django.contrib.admin.sites import AdminSite [as 别名]
# 或者: from django.contrib.admin.sites.AdminSite import register [as 别名]
class TestCflatpagesAdmin(TestCase):
def setUp(self):
self.site = AdminSite()
def test_category_admin(self):
"""
Category admin
"""
self.assertIsNone(self.site.register(models.Category, admin.CategoryAdmin))
def test_page_admin(self):
"""
Page admin
"""
self.assertIsNone(self.site.register(models.CFlatPage, admin.CategorizedFlatPageAdmin))
@override_settings()
def test_page_settings_admin(self):
"""
Page admin
"""
settings.INSTALLED_APPS = settings.INSTALLED_APPS + ["ckeditor"]
self.assertIsNone(self.site.register(models.CFlatPage, admin.CategorizedFlatPageAdmin))
def tearDown(self):
pass
示例2: test_autocomplete_is_onetoone
# 需要导入模块: from django.contrib.admin.sites import AdminSite [as 别名]
# 或者: from django.contrib.admin.sites.AdminSite import register [as 别名]
def test_autocomplete_is_onetoone(self):
class UserAdmin(ModelAdmin):
search_fields = ('name',)
class Admin(ModelAdmin):
autocomplete_fields = ('best_friend',)
site = AdminSite()
site.register(User, UserAdmin)
self.assertIsValid(Admin, ValidationTestModel, admin_site=site)
示例3: test_autocomplete_is_valid
# 需要导入模块: from django.contrib.admin.sites import AdminSite [as 别名]
# 或者: from django.contrib.admin.sites.AdminSite import register [as 别名]
def test_autocomplete_is_valid(self):
class SearchFieldsAdmin(ModelAdmin):
search_fields = 'name'
class AutocompleteAdmin(ModelAdmin):
autocomplete_fields = ('featuring',)
site = AdminSite()
site.register(Band, SearchFieldsAdmin)
self.assertIsValid(AutocompleteAdmin, Song, admin_site=site)
示例4: test_validation_only_runs_in_debug
# 需要导入模块: from django.contrib.admin.sites import AdminSite [as 别名]
# 或者: from django.contrib.admin.sites.AdminSite import register [as 别名]
def test_validation_only_runs_in_debug(self):
# Ensure validation only runs when DEBUG = True
with override_settings(DEBUG=True):
class ValidationTestModelAdmin(ModelAdmin):
raw_id_fields = 10
site = AdminSite()
six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.raw_id_fields' must be a list or tuple.",
site.register,
ValidationTestModel,
ValidationTestModelAdmin,
)
with override_settings(DEBUG=False):
site = AdminSite()
site.register(ValidationTestModel, ValidationTestModelAdmin)
示例5: test_autocomplete_e040
# 需要导入模块: from django.contrib.admin.sites import AdminSite [as 别名]
# 或者: from django.contrib.admin.sites.AdminSite import register [as 别名]
def test_autocomplete_e040(self):
class NoSearchFieldsAdmin(ModelAdmin):
pass
class AutocompleteAdmin(ModelAdmin):
autocomplete_fields = ('featuring',)
site = AdminSite()
site.register(Band, NoSearchFieldsAdmin)
self.assertIsInvalid(
AutocompleteAdmin, Song,
msg=(
'NoSearchFieldsAdmin must define "search_fields", because '
'it\'s referenced by AutocompleteAdmin.autocomplete_fields.'
),
id='admin.E040',
invalid_obj=AutocompleteAdmin,
admin_site=site,
)
示例6: test_validation_only_runs_in_debug
# 需要导入模块: from django.contrib.admin.sites import AdminSite [as 别名]
# 或者: from django.contrib.admin.sites.AdminSite import register [as 别名]
def test_validation_only_runs_in_debug(self):
# Ensure validation only runs when DEBUG = True
try:
settings.DEBUG = True
class ValidationTestModelAdmin(ModelAdmin):
raw_id_fields = 10
site = AdminSite()
self.assertRaisesRegexp(
ImproperlyConfigured,
"'ValidationTestModelAdmin.raw_id_fields' must be a list or tuple.",
site.register,
ValidationTestModel,
ValidationTestModelAdmin,
)
finally:
settings.DEBUG = False
site = AdminSite()
site.register(ValidationTestModel, ValidationTestModelAdmin)
示例7: AdminSite
# 需要导入模块: from django.contrib.admin.sites import AdminSite [as 别名]
# 或者: from django.contrib.admin.sites.AdminSite import register [as 别名]
from django.conf.urls import include, patterns, url
from django.contrib.admin.sites import AdminSite
from multilingual.admin import MultilingualModelAdmin
from .models import Article
SITE = AdminSite()
SITE.register(Article, MultilingualModelAdmin)
urlpatterns = patterns('',
url(r'^admin/', include(SITE.urls)),
)
示例8: AdminSite
# 需要导入模块: from django.contrib.admin.sites import AdminSite [as 别名]
# 或者: from django.contrib.admin.sites.AdminSite import register [as 别名]
from django.contrib.admin.sites import AdminSite
from django.contrib.auth.models import User
from django.contrib.auth.admin import UserAdmin
from pages.models import Page
from pages.admin import PageAdmin
from registration.models import UserProfile
from registration.admin import UserProfileAdmin
publisher_admin = AdminSite('pageadmin')
publisher_admin.register(Page, PageAdmin)
publisher_admin.register(User, UserAdmin)
publisher_admin.register(UserProfile, UserProfileAdmin)
示例9: AdminSite
# 需要导入模块: from django.contrib.admin.sites import AdminSite [as 别名]
# 或者: from django.contrib.admin.sites.AdminSite import register [as 别名]
from django.conf.urls import include, patterns, url
from django.contrib.admin.sites import AdminSite
from multilingual.admin import MultilingualModelAdmin
from .models import Multiling
SITE = AdminSite()
SITE.register(Multiling, MultilingualModelAdmin)
urlpatterns = patterns('',
url(r'^admin/', include(SITE.urls)),
)
示例10: AdminSite
# 需要导入模块: from django.contrib.admin.sites import AdminSite [as 别名]
# 或者: from django.contrib.admin.sites.AdminSite import register [as 别名]
from django.contrib.admin.sites import AdminSite
from django.contrib.auth.models import User
from django.contrib.auth.admin import UserAdmin
from pages.models import Page
from pages.admin import PageAdmin
publisher_admin = AdminSite('pageadmin')
publisher_admin.register(Page, PageAdmin)
publisher_admin.register(User, UserAdmin)
示例11: tuple
# 需要导入模块: from django.contrib.admin.sites import AdminSite [as 别名]
# 或者: from django.contrib.admin.sites.AdminSite import register [as 别名]
used instead of only the tuple (i.e a dict of sites:tuples)
The only issue to resolve when automated is the authorization
issue. How to associate an admin_site with an authorization
evaluation...
"""
from django.contrib.gis import admin
from django.contrib.admin.sites import AdminSite
from photologue.models import Gallery
from photologue.models import GalleryUpload
from photologue.models import Photo
from photologue.admin import PhotoAdmin
from photologue.admin import GalleryAdmin
from funvisis.gallery.admin import FvisGalleryAdmin
from funvisis.geo.buildings.admin import BuildingAdmin
from funvisis.geo.buildings.models import Building
from ..models import BuildingInspection
from .buildinginspection import BuildingInspectionAdmin
admin_site = AdminSite('admin_site')
admin_site.register(BuildingInspection, BuildingInspectionAdmin)
admin_site.register(Building, BuildingAdmin)
admin_site.register(Gallery, FvisGalleryAdmin)
admin_site.register(Photo, PhotoAdmin)
示例12: PolymorphicParentModelAdmin
# 需要导入模块: from django.contrib.admin.sites import AdminSite [as 别名]
# 或者: from django.contrib.admin.sites.AdminSite import register [as 别名]
class PolymorphicParentModelAdmin(admin.ModelAdmin):
"""
A admin interface that can displays different change/delete pages, depending on the polymorphic model.
To use this class, two variables need to be defined:
* :attr:`base_model` should
* :attr:`child_models` should be a list of (Model, Admin) tuples
Alternatively, the following methods can be implemented:
* :func:`get_child_models` should return a list of (Model, ModelAdmin) tuples
* optionally, :func:`get_child_type_choices` can be overwritten to refine the choices for the add dialog.
This class needs to be inherited by the model admin base class that is registered in the site.
The derived models should *not* register the ModelAdmin, but instead it should be returned by :func:`get_child_models`.
"""
#: The base model that the class uses
base_model = None
#: The child models that should be displayed
child_models = None
#: Whether the list should be polymorphic too, leave to ``False`` to optimize
polymorphic_list = False
add_type_template = None
add_type_form = PolymorphicModelChoiceForm
#: The regular expression to filter the primary key in the URL.
#: This accepts only numbers as defensive measure against catch-all URLs.
#: If your primary key consists of string values, update this regular expression.
pk_regex = '(\d+)'
def __init__(self, model, admin_site, *args, **kwargs):
super(PolymorphicParentModelAdmin, self).__init__(model, admin_site, *args, **kwargs)
self._child_admin_site = AdminSite(name=self.admin_site.name)
self._is_setup = False
def _lazy_setup(self):
if self._is_setup:
return
# By not having this in __init__() there is less stress on import dependencies as well,
# considering an advanced use cases where a plugin system scans for the child models.
child_models = self.get_child_models()
for Model, Admin in child_models:
self.register_child(Model, Admin)
self._child_models = dict(child_models)
# This is needed to deal with the improved ForeignKeyRawIdWidget in Django 1.4 and perhaps other widgets too.
# The ForeignKeyRawIdWidget checks whether the referenced model is registered in the admin, otherwise it displays itself as a textfield.
# As simple solution, just make sure all parent admin models are also know in the child admin site.
# This should be done after all parent models are registered off course.
complete_registry = self.admin_site._registry.copy()
complete_registry.update(self._child_admin_site._registry)
self._child_admin_site._registry = complete_registry
self._is_setup = True
def register_child(self, model, model_admin):
"""
Register a model with admin to display.
"""
# After the get_urls() is called, the URLs of the child model can't be exposed anymore to the Django URLconf,
# which also means that a "Save and continue editing" button won't work.
if self._is_setup:
raise RegistrationClosed("The admin model can't be registered anymore at this point.")
if not issubclass(model, self.base_model):
raise TypeError("{0} should be a subclass of {1}".format(model.__name__, self.base_model.__name__))
if not issubclass(model_admin, admin.ModelAdmin):
raise TypeError("{0} should be a subclass of {1}".format(model_admin.__name__, admin.ModelAdmin.__name__))
self._child_admin_site.register(model, model_admin)
def get_child_models(self):
"""
Return the derived model classes which this admin should handle.
This should return a list of tuples, exactly like :attr:`child_models` is.
The model classes can be retrieved as ``base_model.__subclasses__()``,
a setting in a config file, or a query of a plugin registration system at your option
"""
if self.child_models is None:
raise NotImplementedError("Implement get_child_models() or child_models")
return self.child_models
def get_child_type_choices(self):
"""
Return a list of polymorphic types which can be added.
"""
choices = []
for model, _ in self.get_child_models():
#.........这里部分代码省略.........
示例13: AdminSite
# 需要导入模块: from django.contrib.admin.sites import AdminSite [as 别名]
# 或者: from django.contrib.admin.sites.AdminSite import register [as 别名]
list_filter = [
"promotion",
"buy_date",
] # each specified field should be either a BooleanField, CharField, DateField, DateTimeField, IntegerField or ForeignKey.
# inlines = [ChoiceInline]
# date_hierarchy = 'pub_date'
search_fields = ["entry"]
list_per_page = 30
# prepopulated_fields = {"comment": ("entry",)} # may be just for SlugField
radio_fields = {"pack_by": admin.HORIZONTAL}
# readonly_fields = ['add_date']
form = YummyForm
admin_site = AdminSite()
admin_site.register(Category)
admin_site.register(Package)
admin_site.register(Yummy, MyYummyAdmin)
admin_site.index_template = "min_admin.html"
# admin.site.register(Poll)
# class PollAdmin(admin.ModelAdmin):
# fields = ['pub_date', 'question']
#
# admin.site.register(Poll, PollAdmin)
# class PollAdmin(admin.ModelAdmin):
# fieldsets = [
# (None, {'fields': ['question']}),
# ('Date information', {'fields': ['pub_date']}),
# ]
# admin.site.register(Poll, PollAdmin)
示例14: import
# 需要导入模块: from django.contrib.admin.sites import AdminSite [as 别名]
# 或者: from django.contrib.admin.sites.AdminSite import register [as 别名]
from django.contrib import admin
from django.contrib.admin.sites import AdminSite
from evolve.rules.models import (
BuildingKind, Resource, Science, Variant,
Age, City, CitySpecial, Building, BuildOption, Cost, CostLine, Effect,
Building, BuildOption
)
from evolve.rules.forms import EffectForm
site=AdminSite('rules')
site.register(BuildingKind)
site.register(Resource)
site.register(Science)
site.register(Variant)
site.register(Age)
class CitySpecialInline(admin.TabularInline):
model = CitySpecial
class CityAdmin(admin.ModelAdmin):
inlines = [CitySpecialInline]
list_display = ('name', 'resource')
class BuildingAdmin(admin.ModelAdmin):
list_display = ('name', 'kind', 'cost','effect')
list_filter = ('kind',)
class BuildOptionAdmin(admin.ModelAdmin):
list_display = ('building', 'players_needed', 'age')
示例15: import
# 需要导入模块: from django.contrib.admin.sites import AdminSite [as 别名]
# 或者: from django.contrib.admin.sites.AdminSite import register [as 别名]
from flatblocks.models import FlatBlock
from courses.models import (
Course,
Student,
Subject,
Teacher,
Timeslot,
UserProfile)
admin_site = AdminSite()
class CourseAdmin(admin.ModelAdmin):
pass
admin_site.register(Course, CourseAdmin)
admin_site.register(User)
class UserProfileAdmin(admin.ModelAdmin):
pass
admin_site.register(UserProfile, UserProfileAdmin)
class StudentAdmin(admin.ModelAdmin):
pass
admin_site.register(Student, StudentAdmin)