关联对象
class StudentInfo(admin.TabularInline): model = Student extra = 2class GradeAdmin(admin.ModelAdmin): inlines = [StudentInfo]
布尔值显示问题
class StudentAdmin(admin.ModelAdmin):
def gender_text(self): if self.gender: return "男" else: return "女"# 设置页面列的名称gender_text.short_description = "性别"
视图的基本使用
在django中,视图负责对web请求的响应 视图就是一个python函数,在views.py中创建
from django.http import HttpResponsedef index(request): return HttpResponse('Good man')