我添加了一个 bool 字段是从这样的时间开始计算的:
def is_active(self):
if self.inactive_to and self.available_until:
if datetime.date.today()>=self.inactive_to and datetime.date.today()<=self.available_until:
return True
else:
return False
elif self.inactive_to:
if datetime.date.today()>=self.inactive_to:
return True
else:
return False
elif self.available_until:
if datetime.date.today()<=self.available_until:
return True
else:
return False
else:
return True
is_active.short_description = 'Available'
is_active.boolean = True
但如果我尝试将它添加到“list_filter”,我会收到错误消息“'RealtyAdmin.list_filter[0]' 指的是'is_active',它不指代字段。”
我可以避免它,还是添加自动计算的模型字段?
最佳答案
admin 不是 django.db.models.fields 的子类。
这就是 'is_active' 没有引用 Field 的意思。"
是说..
关于python - 如何在 django admin 中对我自己的字段进行过滤器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18370444/