django管理站点覆盖change_list.html

问题描述 投票:0回答:1

它们是否有可能覆盖change_list.html?enter image description here

我只想添加另一个表/列表视图,

models.py

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)

admin.py

class StudentsEnrollmentRecordAdmin(admin.ModelAdmin):
    #inlines = [InLineSubject]
    list_display = ('lrn', 'Student_Users', 'Education_Levels', 'Courses', 'Section', 'Payment_Type', 'Discount_Type' ,'School_Year')
    #list_select_related = ('Student_Users')
    ordering = ('Education_Levels','Student_Users__lrn')
    list_filter = ('Student_Users','Education_Levels','Section','Payment_Type')


    def lrn(self, obj):
        return  obj.Student_Users.lrn
django
1个回答
0
投票

您必须在项目路径中创建一个目录,如下所示:myproject / templates / admin(如果这是您在settings.py中DIRS模板选项中指定的模板设置),然后在此目录中创建一个名为change_list.html的新文件。 。然后,Django将使用它而不是默认值。

此外,您还可以使用这个新的change_list.html模板进行扩展/使用。

有关覆盖和替换默认管理和注册模板的更多参考,另请参阅:https://docs.djangoproject.com/en/2.2/ref/contrib/admin/->搜索“覆盖管理模板”

© www.soinside.com 2019 - 2024. All rights reserved.