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鎵归噺鐢熸垚涓婅璁板綍的主要内容,如果未能解决你的问题,请参考以下文章
odoo 瀵煎叆鏂囦欢xml鍒朵綔,浣跨敤csv 鏂囦欢鍒朵綔xml 鏂囦欢