我面临着在管理表单中作为内联添加字段的问题。我的模型是如下所示:你知道吗
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
字段。你知道吗
我似乎想不出解决办法,如何着手解决这个问题?你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐