Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

Django Admin - 包含成员


在管理员界面中包含成员

要将 Member 模型包含在管理员界面中,我们必须告诉 Django 该模型应该在管理员界面中可见。

这在名为 admin.py 的文件中完成,该文件位于您的应用文件夹中,在本例中为 members 文件夹。

打开它,它应该如下所示

my_tennis_club/members/admin.py:

from django.contrib import admin

# Register your models here.

在此处插入几行代码以使 Member 模型在管理员页面中可见

my_tennis_club/members/admin.py:

from django.contrib import admin
from .models import Member

# Register your models here.
admin.site.register(Member)

现在返回浏览器,您应该会得到此结果

单击 Members 并查看我们之前在本教程中插入的五条记录


更改显示

在上图中的列表中,我们看到“Member object (1)”,“Member object (2)”等,这可能不是您希望在列表中显示的数据。

最好改为显示“firstname”和“lastname”。

这可以通过更改 models.py 和/或 admin.py 文件中的一些设置轻松完成。您将在下一章中详细了解此内容。



×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.