本文整理汇总了Python中django.contrib.admin.ModelAdmin.changelist_view方法的典型用法代码示例。如果您正苦于以下问题:Python ModelAdmin.changelist_view方法的具体用法?Python ModelAdmin.changelist_view怎么用?Python ModelAdmin.changelist_view使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.admin.ModelAdmin
的用法示例。
在下文中一共展示了ModelAdmin.changelist_view方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: changelist_view
# 需要导入模块: from django.contrib.admin import ModelAdmin [as 别名]
# 或者: from django.contrib.admin.ModelAdmin import changelist_view [as 别名]
def changelist_view(self, request, extra_context=None):
if extra_context is None:
extra_context = {}
extra_context['menu_option_types'] = MenuOption.MODEL_TYPE_CHOICES
extra_context['app_label'] = _("GDT Nav")
extra_context['menu_groups'] = MenuGroup.objects.order_by('name')
return ModelAdmin.changelist_view(self, request, extra_context)
示例2: changelist_view
# 需要导入模块: from django.contrib.admin import ModelAdmin [as 别名]
# 或者: from django.contrib.admin.ModelAdmin import changelist_view [as 别名]
def changelist_view(self, request, extra_context=None):
try:
action = self.get_actions(request)[request.POST['action']][0]
action_acts_on_all = action.acts_on_all
except (KeyError, AttributeError):
action_acts_on_all = False
if action_acts_on_all:
post = request.POST.copy()
post.setlist(helpers.ACTION_CHECKBOX_NAME,
self.model.objects.values_list('pk', flat=True))
request.POST = post
return ModelAdmin.changelist_view(self, request, extra_context)
示例3: changelist_view
# 需要导入模块: from django.contrib.admin import ModelAdmin [as 别名]
# 或者: from django.contrib.admin.ModelAdmin import changelist_view [as 别名]
def changelist_view(self, request, extra_context=None):
response = ModelAdmin.changelist_view(self, request, extra_context=extra_context)
queryset = response.context_data['cl'].get_query_set(request)
queryset_len = queryset.count()
if queryset_len == 0:
response.context_data['person'] = None
else:
if request.GET.has_key('q'):
try:
response.context_data['person'] = Person.objects.get(name__icontains=request.GET['q'])
except:
response.context_data['person'] = None
else:
min_date = queryset.aggregate(Min('date'))['date__min']
max_date = queryset.aggregate(Max('date'))['date__max']
start_debt = Debt.objects.filter(person=response.context_data['person'], date__lt=min_date).aggregate(Sum('total'))['total__sum'] or 0.0
final_debt = Debt.objects.filter(person=response.context_data['person'], date__lte=max_date).aggregate(Sum('total'))['total__sum'] or 0.0
response.context_data['start_debt'] = start_debt
response.context_data['final_debt'] = final_debt
response.context_data['period_debt'] = final_debt - start_debt
return response