本文整理汇总了Python中django.contrib.admin.ModelAdmin.message_user方法的典型用法代码示例。如果您正苦于以下问题:Python ModelAdmin.message_user方法的具体用法?Python ModelAdmin.message_user怎么用?Python ModelAdmin.message_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.admin.ModelAdmin
的用法示例。
在下文中一共展示了ModelAdmin.message_user方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_active_brother
# 需要导入模块: from django.contrib.admin import ModelAdmin [as 别名]
# 或者: from django.contrib.admin.ModelAdmin import message_user [as 别名]
def make_active_brother(modeladmin, request, queryset):
group = Group.objects.get(name='Active Brother')
for user in queryset:
user.groups.add(group)
ModelAdmin.message_user(self=modeladmin, request=request,
message='Selected users were added to the '
'Active Brother group')
示例2: unpublish_page
# 需要导入模块: from django.contrib.admin import ModelAdmin [as 别名]
# 或者: from django.contrib.admin.ModelAdmin import message_user [as 别名]
def unpublish_page(modeladmin: admin.ModelAdmin, request: HttpRequest, queryset: QuerySet):
pages_updated = queryset.update(published=False)
if pages_updated == 1:
message = '1 page was'
else:
message = '{:d} page were'.format(pages_updated)
modeladmin.message_user(request, '{:s} successfully marked as published.'.format(message))
示例3: merge
# 需要导入模块: from django.contrib.admin import ModelAdmin [as 别名]
# 或者: from django.contrib.admin.ModelAdmin import message_user [as 别名]
def merge(modeladmin, request, queryset):
main = queryset[0]
tail = queryset[1:]
related = main._meta.get_all_related_objects()
valnames = dict()
for r in related:
valnames.setdefault(r.related_model, []).append(r.field.name)
manyrelated = main._meta.get_all_related_many_to_many_objects()
manyvalnames = dict()
for r in manyrelated:
manyvalnames.setdefault(r.related_model, []).append(r.field.name)
for place in tail:
for model, field_names in valnames.items():
for field_name in field_names:
model.objects.filter(**{field_name: place}).update(**{field_name: main})
for model, field_names in manyvalnames.items():
for field_name in field_names:
for manytomany in model.objects.filter(**{field_name: place}):
manyfield = getattr(manytomany, field_name) # gets attribute from string
manyfield.remove(place)
manyfield.add(main)
place.delete()
# merge all TeamsOnTournament on same Tournament for this Team
modelname = modeladmin.__class__.__name__
if modelname is 'TeamAdmin':
tours = []
team = Team.objects.get(name=main)
totm = TeamOnTournament.objects.filter(team=team)
for tour in totm:
if tour.tournament not in tours:
tours.append(tour.tournament)
for tour in tours:
totm = TeamOnTournament.objects.filter(team=team).filter(tournament=tour)
if len(totm) > 1:
for instance in totm[1:]:
for player in instance.players.all():
totm[0].players.add(player)
instance.delete()
ModelAdmin.message_user(modeladmin, request, 'sloučeno, v objektu můžete zvolit výsledné jméno')
示例4: delete_statistics
# 需要导入模块: from django.contrib.admin import ModelAdmin [as 别名]
# 或者: from django.contrib.admin.ModelAdmin import message_user [as 别名]
def delete_statistics(modeladmin: admin.ModelAdmin, request: HttpRequest, queryset: QuerySet):
for l in queryset:
HitModel.objects.filter(for_link=l).delete()
modeladmin.message_user(request, 'Statistics deleted')