本文整理汇总了Python中django.contrib.admin.ModelAdmin.add_view方法的典型用法代码示例。如果您正苦于以下问题:Python ModelAdmin.add_view方法的具体用法?Python ModelAdmin.add_view怎么用?Python ModelAdmin.add_view使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.admin.ModelAdmin
的用法示例。
在下文中一共展示了ModelAdmin.add_view方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_view
# 需要导入模块: from django.contrib.admin import ModelAdmin [as 别名]
# 或者: from django.contrib.admin.ModelAdmin import add_view [as 别名]
def add_view(self, request, form_url='', extra_context=None):
context = self.get_context_data(**(extra_context or {} ))
return DjangoModelAdmin.add_view(self, request, form_url, context)
示例2: reverse
# 需要导入模块: from django.contrib.admin import ModelAdmin [as 别名]
# 或者: from django.contrib.admin.ModelAdmin import add_view [as 别名]
extra_context['menu_option_types'] = MenuOption.MODEL_TYPE_CHOICES
if option_type is not None:
# Hack to detect if we need to specify the javascript url or not.
try:
reverse('admin:jsi18n')
except NoReverseMatch, e:
extra_context['jsurl'] = "../../../../jsi18n/"
option_type = int(option_type)
type = dict(MenuOption.MODEL_TYPE_CHOICES)[option_type]
extra_context['crumb'] = _("Add %(name)s") % {'name':type}
admin_class = self.fetch_admin_class(option_type)
admin_instance = admin_class(MenuOption, self.admin_site)
return admin_instance.add_view(request, form_url, extra_context)
else:
extra_context['default_form'] = True
return ModelAdmin.add_view(self, request, form_url, extra_context)
def change_view(self, request, object_id, extra_context=None):
try:
obj = self.queryset(request).get(pk=int(object_id))
option_type = obj.option_type
except (self.model.DoesNotExist, ValueError), e:
option_type = None
if extra_context is None:
extra_context = {}
extra_context['app_label'] = _("GDT Nav")
extra_context['menu_option_types'] = MenuOption.MODEL_TYPE_CHOICES
if option_type is not None:
option_type = int(option_type)
extra_context['crumb'] = obj.name
admin_class = self.fetch_admin_class(option_type)