1

我面临在管理表单中将字段添加为内联的问题。我的模型如下:-

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')}),
    )

内联 forAppliedForCourse像往常一样工作,但问题在于ProfileEnrollmentInline我需要在内联中显示模型的icourse, iclass, batch&enroll_num字段Enrollment

我似乎无法弄清楚解决方案,如何解决这个问题?

4

0 回答 0