django中对字段的设置

    • 对字段的设置

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
    • django中的某些单词的所代表的东西

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'>
    • django项目标题和页面标题设置

admin.site.site_header = '羊智能配方系统1'
admin.site.site_title = '羊智能配方系统2'

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阿旺.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值