CRM admin浣跨敤actions鎵归噺鐢熸垚涓婅璁板綍

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CRM admin浣跨敤actions鎵归噺鐢熸垚涓婅璁板綍相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/exce' title='exce'>exce   鏌ヨ   瀵硅薄   res   out   djang   cep   editable   self   

浣跨敤actions瀛楁閲岀殑鍑芥暟澶勭悊閫夋嫨涓€涓彮绾х殑涓婅璁板綍锛岀劧鍚庡垱寤鸿繖涓彮绾у鐢熺殑瀛︿範璁板綍

 

1銆佸湪admin.py鏂囦欢涓姞涓?/span>CourseRecordAdmin锛孲tudyRecordAdmin

actions瀛楁閲岄潰鐨勫嚱鏁颁細鏈変笁涓姹傚弬鏁帮細self==CourseRecordAdmin,rquest ==request.Post,quertset==<QuerySet [<CourseRecord: 涓婃捣娴︿笢 python鍏ㄦ爤 4 1>

 

閫氳繃璇锋眰鐨剄ueryset鐨勫€间娇鐢╡nrollment_set鑾峰彇enrollment琛ㄤ腑鐨勬墍鏈夋暟鎹?/span>

queryset[0].from_class.enrollment_set.all()

 

鐢熸垚杩欎釜鐝骇鐨勫鐢熷涔犺褰曚娇鐢╞ulk_creact鍘绘壒閲忓垱寤猴紝鍏堟妸鏁版嵁閮藉瓨鍒颁竴涓彉閲忛噷闈?/span>

models.StudyRecord.objects.bulk_create(study_obj)

 

濡傛灉涓彮绾х殑瀛︾敓璁板綍鍒涘缓浜嗭紝鍐嶆鍘诲垱寤哄氨浼氭姤濡備笅鐨勯敊锛岃В鍐虫槸鐢╰ry鎹曟崏

#(1062, "Duplicate entry 鈥?-1鈥?for key 鈥榗rm_studyrecord_student_id_course_record_id_24d12464_uniq鈥?)

 

鍦ㄥ垱寤哄涔犺褰昐tudyRecord鐨勬暟鎹椂鍊欙紝student杩欎釜瀛楁鏄竴涓閿瓻nrollment琛ㄧ殑瀵硅薄,鎴戞槸寮勬垚浜嗚幏鍙栦竴涓璞′笅闈㈢殑涓€涓€?/span>

#print("enroll_obj.customer",enroll_obj.customer)锛屽氨浼氭姤濡備笅閿欒锛?br />
 #Cannot assign "<Customer: 190837349120>": "StudyRecord.student" must be a "Enrollment" instance.

 

django浣跨敤list_editable灞炴€у彲浠ョ紪杈戯紝short_description actions鍑芥暟鍚嶆樉绀轰腑鏂囧悕

 

杩欎釜灏忓姛鑳界殑鎵€鏈変唬鐮佸涓嬶細

class CourseRecordAdmin(admin.ModelAdmin):
    
    list_display =["from_class","teacher","outline","day_num"]
    actions = ["initialization_course_record"]
    def initialization_course_record(self,request,queryset):
        #鍙兘閫夋嫨涓€鏉′竴涓彮绾х殑涓婅璁板綍
        print("self,request,queryset:",self,request,queryset)
        if len(queryset)>1:
            return HttpResponse("鍙兘閫夋嫨涓€鏉¤褰?/span>")
        #鎵惧嚭杩欎釜鐝姤鍚嶇殑瀛︾敓鏁?/span>
        #print("queryset[0]:",queryset[0].from_class.enrollment_set.all())
        #(1062, "Duplicate entry 鈥?-1鈥?for key 鈥榗rm_studyrecord_student_id_course_record_id_24d12464_uniq鈥?)
        #Cannot assign "<Customer: 190837349120>": "StudyRecord.student" must be a "Enrollment" instance.
        study_obj=[]
        for enroll_obj in queryset[0].from_class.enrollment_set.all():
            #print("enroll_obj.customer",enroll_obj.customer)
            #濡傛灉鏈変簡灏辨煡璇㈡病鏈夊氨鍒涘缓锛屼笉鐒朵細鎶ュ敮涓€鎬ч敊璇?/span>
            #杩欎釜鏄瘡涓€鏉′竴鏉$殑鎻愪氦浜嬬墿锛屽鏋滄暟鎹お澶х殑璇濇€ц兘浼氭瘮杈冨樊
            # models.StudyRecord.objects.get_or_create(student=enroll_obj,
            #                                   course_record=queryset[0],
            #                                   attendance =0,
            #                                   score=0)
            study_obj.append(models.StudyRecord(
                student=enroll_obj,
                course_record=queryset[0],
                attendance=0,
                score=0))
        try:
            #bulk_create鍙互鍒涘缓寰堝涓絾鏄繖涓簨鍔℃槸鎻愪氦鐨勫50鏉★紝50鏉″け璐?/span>
            models.StudyRecord.objects.bulk_create(study_obj)
            return redirect("/admin/crm/studyrecord/")
        except Exception as e:
            return HttpResponse("鏈変簺鏁版嵁宸茬粡鏈夊涔犺褰曚簡")
    #actions鍑芥暟鍚嶆樉绀轰腑鏂囧悕short_description
    initialization_course_record.short_description = "鍒濆鍖栨湰鑺備笂璇捐褰?/span>"

class StudyRecordAdmin(admin.ModelAdmin):
    list_display=["student","course_record","attendance","score"]
    list_filter = ["course_record","score","attendance"]
    #鍙紪杈戠殑
    list_editable = ["score","attendance"]

 

 

 

以上是关于CRM admin浣跨敤actions鎵归噺鐢熸垚涓婅璁板綍的主要内容,如果未能解决你的问题,请参考以下文章

K8s浣跨敤YAML鏂囦欢鍒涘缓璧勬簮

odoo 瀵煎叆鏂囦欢xml鍒朵綔,浣跨敤csv 鏂囦欢鍒朵綔xml 鏂囦欢

鎵归噺淇敼鏂囦欢鍚嶅瓧

鎵归噺鎶撳寘

Jmeter 缂栧啓鎺ュ彛娴嬭瘯鐢ㄤ緥閬囧埌鐨勯棶棰樺強瑙e喅鍔炴硶

SaltStack 鎵归噺鎿嶄綔Windows