我的 models.py 文件中有一个 BooleanField。
我希望它对所有管理员/超级用户默认为 True,而我希望它对所有其他用户默认为 False。
为此,我不想在我的 html 中使用 if-else 模板标签,我希望得到一个更干净的解决方案。
就像是:
field_name = models.BooleanField(
if author.is_superuser:
default = True
else:
default=False
)
任何帮助表示赞赏。这里的作者是模型类“Post”的作者。
编辑1:我需要的user.is_superuser实际上是作者的用户。我需要验证博客文章的作者是否是超级用户,然后为布尔字段分配默认值。