Django管理员站点2外键

时间:2019-10-28 22:49:54

标签: django

class StudentsEnrollmentRecord(models.Model):
    Student_Users = models.ForeignKey(StudentProfile, related_name='students', on_delete=models.CASCADE,null=True)
    School_Year = models.ForeignKey(SchoolYear, related_name='+', on_delete=models.CASCADE, null=True, blank=True)
    Courses = models.ForeignKey(Course, related_name='+', on_delete=models.CASCADE, null=True, blank=True)
    Section = models.ForeignKey(Section, related_name='+', on_delete=models.CASCADE, null=True,blank=True)
    Payment_Type = models.ForeignKey(PaymentType, related_name='+', on_delete=models.CASCADE, null=True)
    Education_Levels = models.ForeignKey(EducationLevel, related_name='+', on_delete=models.CASCADE,blank=True,null=True)
    Remarks = models.TextField(max_length=500,null=True,blank=True)
    def __str__(self):
        suser = '{0.Student_Users}  {0.Education_Levels}'
        return suser.format(self)

class ScheduleOfPayment(models.Model):
    Pending_Request = [
       ('Active', 'Active'),
       ('Inactive', 'Inactive'),
    ]
    Education_Levels = models.ForeignKey(EducationLevel, related_name='+', on_delete=models.CASCADE, blank=True, null=True)
    Courses = models.ForeignKey(Course, related_name='+', on_delete=models.CASCADE,blank=True, null=True)
    Payment_Type = models.ForeignKey(PaymentType, related_name='+', on_delete=models.CASCADE, blank=True, null=True)
    Display_Sequence = models.IntegerField(blank=True, null=True)
    Date = models.DateField(null=True,blank=True)
    Amount = models.FloatField(null=True, blank=True)
    Remark = models.CharField(max_length=500,blank=True, null=True)
    Status = models.CharField(max_length=500, null=True, choices=Pending_Request,blank=True)

/管理员

StudentsEnrollmentRecordAdmin enter image description here

class StudentsEnrollmentRecordAdmin(admin.ModelAdmin):
    list_display = ('lrn', 'Student_Users', 'Education_Levels', 'Courses', 'Section', 'Payment_Type', 'amount' ,'School_Year')
    ordering = ('Education_Levels','Student_Users__lrn')
    list_filter = ('Student_Users','Education_Levels','Section','Payment_Type')

admin.site.register(StudentsEnrollmentRecord,StudentsEnrollmentRecordAdmin)

付款时间表 enter image description here

@admin.register(ScheduleOfPayment)
class ScheduleOfPayment(admin.ModelAdmin):
    list_display = ('Education_Levels','Payment_Type','Display_Sequence','Date','Amount','Remark','Status')
    ordering = ('Education_Levels','Payment_Type','Display_Sequence')
    list_filter = ('Education_Levels','Payment_Type')

如何在Django管理网站中合并这两个表/列表视图?请帮助我,我已经研究了3天,但是我找不到解决这个问题的方法。

更新,我想这样显示 enter image description here

0 个答案:

没有答案