Django-โปรไฟล์-ขยายเป็น app Django ที่ให้ระบบโปรไฟล์ของผู้ใช้ขยายสำหรับ Django ออกแบบมาเพื่อให้ผู้ใช้ข้อมูลส่วนตัวรูปแบบที่เรียบง่ายที่จะขยาย
แนวความคิด (และโค้ดบางส่วน) จะถูกยืมมาจาก FeinCMS (https://github.com/matthiask/feincms) รุ่นหน้า
ที่จะใช้โมดูลโปรไฟล์เพิ่มโปรไฟล์เพื่อ INSTALLED_APPS ของคุณ
ก่อนที่จะดำเนินการกับ syncdb manage.py คุณต้องเพิ่มรายละเอียดบางส่วนขยาย โมดูลโปรไฟล์ไม่ได้เพิ่มอะไรกับรูปแบบการใช้งานโดยค่าเริ่มต้น
โมดูลขยายรายละเอียด
ส่วนขยายเป็นวิธีที่จะเพิ่มฟังก์ชันการทำงานมักจะใช้รูปแบบรายละเอียด นามสกุลเป็นโมดูลหลามมาตรฐานที่มีการลงทะเบียน () วิธีการที่จะได้รับการเรียกร้องการลงทะเบียนขยาย ลงทะเบียน () วิธีการรับรุ่นที่ตัวเองและระดับผู้ดูแลระบบแบบ ProfileAdmin เป็นข้อโต้แย้ง
ส่วนขยายที่สามารถใช้งานได้โดยการเพิ่มต่อไปนี้เพื่อไฟล์ models.py ที่จะต้องดำเนินการต่อไป:
จาก profiles.models รายละเอียดการนำเข้า
& nbsp; & nbsp; & nbsp; Profile.register_extensions ('ชื่อ', 'ภาพ', 'ที่อยู่', 'profiles.modules.options.extensions.options')
ถ้านามสกุลต้องมีรูปแบบของตัวเอง (เช่นการขยายตัวเลือก) จากนั้นการตรวจสอบที่มีรูปแบบก็จะต้องมีการเพิ่มเข้ามาใน INSTALLED_APPS ของคุณ
การเพิ่มส่วนขยาย
ในการเพิ่มขยายการสร้างโมดูลหลามที่กำหนดฟังก์ชั่นลงทะเบียนที่ยอมรับระดับรายละเอียดและระดับ ProfileAdmin เป็นข้อโต้แย้งและปรับเปลี่ยนพวกเขาเป็นที่ต้องการ
นี่คือส่วนขยายที่อยู่ (โปรไฟล์ / นามสกุล / address.py):
จากรุ่นนำเข้า django.db
& nbsp; & nbsp; & nbsp; จากการนำเข้า ugettext_lazy django.utils.translation เป็น _
& nbsp; & nbsp; & nbsp; def ลงทะเบียน (CLS, admin_cls):
& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; cls.add_to_class ('address1', models.CharField (max_length = 255, verbose_name = _ ('ที่อยู่'), null = True, ว่างเปล่า = True))
& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; cls.add_to_class ('address2', models.CharField (max_length = 255, verbose_name = _ ('ที่อยู่ 2'), null = True, ว่างเปล่า = True))
& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; cls.add_to_class ('เมือง', models.CharField (max_length = 255, verbose_name = _ ('เมือง / เมือง'), null = True, ว่างเปล่า = True))
& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; cls.add_to_class ('ภูมิภาค', models.CharField (max_length = 255, verbose_name = _ ('เขต / รัฐ / จังหวัด'), null = True, ว่างเปล่า = True))
& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; cls.add_to_class ('รหัสไปรษณีย์', models.CharField (max_length = 15, verbose_name = _ ('รหัสไปรษณีย์'), null = True))
& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; cls.add_to_class ('ประเทศ', models.ForeignKey ('countries.Country', null = True, ว่างเปล่า = True))
& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; cls.add_to_class ('โทรศัพท์', models.CharField (max_length = 32, verbose_name = _ ('หมายเลขโทรศัพท์มือถือ'), null = True, ว่างเปล่า = True))
& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; ถ้า admin_cls:
& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; admin_cls.search_fields + = ['address1', 'address2', 'เมือง', 'ภูมิภาค', 'รหัสไปรษณีย์']
& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; admin_cls.list_display_filter + = ['ประเทศ']
& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; ถ้า admin_cls.fieldsets:
& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; admin_cls.fieldsets.append ((_ ('ที่อยู่') {
'ทุ่ง': ['address1', 'address2', 'เมือง', 'ภูมิภาค', 'รหัสไปรษณีย์', 'ประเทศ', 'โทรศัพท์'],
'เรียน' ('ยุบ',)
}))
. เพิ่ม 'incuna.countries' เพื่อ INSTALLED_APPS สำหรับการใช้ส่วนขยายที่อยู่
ต้องการ
- หลาม
- Django
ความคิดเห็นที่ไม่พบ