django xadmin save_models

django   xadmin   在修改数据时的连带操作

class ProjectAdmin(object):
    list_display = [
        'code', 'pname', 'wheel', 'clientPerson', 'get_branchinfo_nums','get_branchinfoInput_nums',
        'monthCurrent', 'state', 'protype',  'go_to','excel']
    search_fields = [
        'pname', 'code', 'wheel', 'clientPerson', 'inputCount', 'checkCount', 'complaining', 'complained',
        'monthCurrent',
        'state', 'protype']
    list_filter = [
        'pname', 'code', 'wheel', 'clientPerson', 'inputCount', 'checkCount', 'complaining', 'complained',
        'monthCurrent', 'state', 'protype']
    list_editable = ['pname', 'wheel','clientPerson','state']
    list_display_links = ['code']


   # qds=super().get_list_queryset()

##  修改数据时的连带操作

    def save_models(self):
        print("save_models")
        branchinfo.objects.filter(projectId=self.new_obj.id).update(month=self.new_obj.monthCurrent)
        #self.new_obj.Project = self.request.Project
        super().save_models()
    # inlines = [branchinfoInline]


    # def queryset(self):
    #     #     # 重载queryset方法,来过滤出我们想要的数据的
    #     #     #user=User.objects.get(id=userID)
    #     #    # print(user)
    #     #     #self.request.user
    #     #     qs = super(ProjectAdmin, self).queryset()
    #     #     # 只显示is_banner=True的课程
    #     #     qs = qs.exclude(protype=str(3))
    #     #
    #     #     return qs


##  设置  列表根据用户  权限而现实 内容
    def get_list_queryset(self):
        request=self.request
        user=request.user
        print(user.protype)
        qs = super().get_list_queryset()
        if user.protype == 3:
            qs=super().get_list_queryset().filter(protype='3')
        elif user.protype == 5:
            qs=super().get_list_queryset().filter(Q(protype='5')|Q(protype='6'))
        elif user.protype == 0:
            qs=super().get_list_queryset()
        elif user.protype == 7:
            qs=super().get_list_queryset().filter(protype='7')
        else:
            qs = super().get_list_queryset().exclude(protype='3')
        return qs

你可能感兴趣的:(个人经验)