管理フォームにフィールドをインラインとして追加するという問題に直面しています。私のモデルは次のとおりです:-
class Enrollment(BaseTableCore):
iclass = models.ForeignKey(InstituteClass,blank=True,null=True,on_delete=models.SET_NULL )
batch = models.ForeignKey(Batch,blank=True,null=True,on_delete=models.SET_NULL)
icourse = models.ForeignKey(InstituteCourse,blank=True,null=True,on_delete=models.SET_NULL)
enroll_num=models.CharField(max_length=20)**
class RegistrationProfile(models.Model):
user = models.OneToOneField(User,related_name='userregistrationprofile')
activeflag = models.BooleanField(blank=True) # This would be true when the student profile is activated by admin.
usertype = models.IntegerField(choices=USER_TYPES)
email = models.EmailField(null=True,blank=True)
dob = models.DateField(blank=True,null=True)
gender = models.IntegerField(choices=GENDER_CHOICE,null=True,blank=True)
mobile_no = models.IntegerField(null=True,blank=True,help_text="Please Enter Your Mobile No : ")
enrollment = models.ManyToManyField(Enrollment, through='ProfileEnrollment')
courses_applied = models.ManyToManyField(InstituteCourse,through='AppliedForCourse')
class ProfileEnrollment(models.Model):
profile = models.ForeignKey(RegistrationProfile)
enrollment = models.ForeignKey(Enrollment)
class AppliedForCourse(models.Model):
profile = models.ForeignKey(RegistrationProfile)
courses = models.ForeignKey(InstituteCourse)
batch = models.ForeignKey(Batch)
問題が発生している管理フォームは次のとおりです。
class AppliedForCourseInline(admin.TabularInline):
model = AppliedForCourse
fieldsets = ((None,{
'fields':('courses','batch')}),
)
extra =0
class ProfileEnrollementInline(admin.TabularInline):
model = ProfileEnrollment
extra = 0
class RegistrationProfileAdmin(admin.ModelAdmin):
form = RegistrationProfileAdminForm
inlines = [AppliedForCourseInline,ProfileEnrollementInline]
fieldsets = ((None,{
'fields':('user','activeflag','usertype')}),
)
のインラインAppliedForCourse
は通常どおり機能していますが、インラインでモデルの、、&フィールドProfileEnrollmentInline
を表示する必要があるため、 の要件に問題があります。icourse
iclass
batch
enroll_num
Enrollment
解決策がわからないようです。この問題をどのように進めればよいですか?