当前位置: 首页>>代码示例>>Python>>正文


Python ModelAdmin.message_user方法代码示例

本文整理汇总了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')
开发者ID:SheldonB,项目名称:SigEp-WebApp,代码行数:9,代码来源:admin.py

示例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))
开发者ID:django-tutorial,项目名称:shortlink,代码行数:9,代码来源:page.py

示例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')
开发者ID:thran,项目名称:ufobal-web,代码行数:49,代码来源:admin.py

示例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')
开发者ID:django-tutorial,项目名称:shortlink,代码行数:6,代码来源:link.py


注:本文中的django.contrib.admin.ModelAdmin.message_user方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。