-
fieldsets = (
('羊只信息', {'fields': ['sheep_kind','name','weight','day_age','ADG',]}),
('羊只数据', {'classes': ('wide', 'extrapretty'),
'fields': ['DMI','ME_content','CP_content','Ca_content','P_content','S_content','roughage_uplimit','energy_uplimit','protein_uplimit','premix_uplimit','S_uplimit','soda_uplimit','notes',]})
)
exclude = [] # 增加页面不显示字段
# 在列表页显示的字段,默认会显示所有字段,有对应的方法可以重写
list_display = ('__str__',)
list_display = ['change','sheep_kind','name','weight','day_age','ADG','DMI','ME_content','CP_content','Ca_content','P_content','S_content','roughage_uplimit','energy_uplimit','protein_uplimit','premix_uplimit','S_uplimit','soda_uplimit','notes',]
list_filter = ['sheep_kind','name'] #页面展示过滤器
readonly_fields = ['sheep_kind','name','weight','day_age','ADG',] #设置编辑页面只读字段
exclude_display = [] #隐藏页面展示字段
exclude_filter = [] #隐藏展示过滤器
search_fields = []
ordering = ('-id',)
list_per_page = 20
# 对于外键字段的搜索,关联字段__被关联字段
search_fields = ['animal__self_num','house__house_num']
# 将字段的select下拉框变成按钮的形式进行选择
# 您可以选择使用HORIZONTAL还是VERTICAL从 django.contrib.admin模块中选择。
# HORIZONTAL横向排列
# VERTICAL竖向排列
radio_fields = {'state': admin.HORIZONTAL}
raw_id_fields = ['name',]
# 外键字段搜索
autocomplete_fields = ('name',)
# 时间筛选格式
date_hierarchy = 'date'
# 在增加详情页面添加自定义的只读字段
readonly_fields = ('address_report',)
def address_report(self, instance):
return 'xxx'
address_report.short_description = "自定义只读字段"
# 设置show_full_result_count以控制是否应在过滤的管理页面上显示对象的全部数量。如果将此选项设置为True, 则搜索框旁会显示类似的文本99 results(103 total);设置为False显示99 results(Show all)
show_full_result_count = False
# 如果要禁用某些列的排序,请使用sortable_by设置,将 希望 排序的字段 填写 在sortable_by元组或者列表中。
sortable_by = ()
#隐藏删除按钮
actions = None
-
print(obj) #obj表示新增的对象,具体值由model中的 def __str__(self) 决定
print(self) # animal.AnimalInfoAdmin
# qs 表示model中def __str__(self)设置的类型的所有对象
qs=super().get_queryset(request) #输出<QuerySet [<BreedingInfo: 00000000000000019---031001F2021007>, <BreedingInfo: 00000000000000019---031001F2021007>, <BreedingInfo: 031001F2021006---031001M2021005>, <BreedingInfo: 031001M2021005---031001M02022023>]
title=obj.__str__() #obj是对象; title=obj.__str()__是字符串;
print('obj的值和类型',obj,type(obj)) #obj的值和类型 1111111111111111111---33333333333333333333 <class 'apps.breed.models.BreedingInfo'>
print('obj.__str()__的值和类型',title,type(title)) #obj.__str()__的值和类型 1111111111111111111---33333333333333333333 <class 'str'>
breeding = obj.breeding
print('breeding的具体值',breeding,'类型',type(breeding)) #breeding的具体值 1111111111111111111---33333333333333333333 类型 <class 'apps.breed.models.BreedingInfo'>
-
admin.site.site_header = '羊智能配方系统1'
admin.site.site_title = '羊智能配方系统2'