django管理站点自定义change_list.html

时间:2019-11-21 15:33:18

标签: django

是否可以在Django管理站点中更改change_list的视图? 就像在图片上 enter image description here 这是我的模型。py

class gradingPeriod(models.Model):
    Grade_Scales_Setting= models.ForeignKey(gradeScalesSetting, related_name='+', on_delete=models.CASCADE,null=True)
    Description = models.CharField(max_length=500,blank=True)
    Display_Sequence = models.IntegerField()
    Status = models.CharField(max_length=500, null=True, choices=Pending_Request,blank=True)
    StartDate=models.DateField(null=True,blank=True)
    EndDate=models.DateField(null=True,blank=True)

class gradingPeriodsSetting(models.Model):
    School_Year = models.ForeignKey(SchoolYear, related_name='+', on_delete=models.CASCADE, null=True, blank=True)
    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, null=True, blank=True)
    NumberOfGradingPeriods = models.IntegerField(blank=True, null=True)

class gradingPeriodsSummary(models.Model):
    Grading_Periods_Setting= models.ForeignKey(gradingPeriodsSetting, related_name='+', on_delete=models.CASCADE,null=True)
    Description = models.CharField(max_length=500,blank=True)
    Display_Sequence = models.IntegerField()
    Start_Grading_Period= models.ForeignKey(gradingPeriod, related_name='+', on_delete=models.CASCADE,null=True)
    End_Grading_Period= models.ForeignKey(gradingPeriod, related_name='+', on_delete=models.CASCADE,null=True)

我不知道如何在admin.py上对其进行编码,我希望在自己的change_list中进行什么设计

1 个答案:

答案 0 :(得分:0)

您应该通过更改change_list_template属性来编辑admin.py文件。

例如:

class MyFirstobjectAdmin(admin.ModelAdmin):
    change_list_template = path.to.my.custom.view.function

您可以在https://docs.djangoproject.com/en/2.2/ref/contrib/admin/

上看到更多内容

编辑 在模型中添加样本

@admin.register(gradingPeriod)
class gradingPeriodAdmin(admin.ModelAdmin):
    change_list_template = 'myapp/mymodel_change_list.html'

@admin.register(gradingPeriodsSetting)
class gradingPeriodsSettingAdmin(admin.ModelAdmin):
    change_list_template = 'myapp/mymodel_change_list.html'

@admin.register(gradingPeriodsSummary)    
class gradingPeriodsSummaryAdmin(admin.ModelAdmin):
    change_list_template = 'myapp/mymodel_change_list.html'