[英]django returns blank /empty string as None
Django app is displaying 'None' value in the text field, if the database (postgres) return empty string. 如果数据库(postgres)返回空字符串,Django应用程序在文本字段中显示“无”值。
Any idea, how could i display empty string? 任何想法,我怎么能显示空字符串? any help would be much appreciated
任何帮助将非常感激
Not sure how big the application is, but if it's not too much of a hassle you can just update the models that have "None"
. 不确定应用程序有多大,但如果不是太麻烦,你可以只更新具有
"None"
的模型。
Something like: 就像是:
ModelA.objects.filter(the_field="None").update(the_field=None) ModelB.objects.filter(another_field="None").update(another_field=None)
If there are too many fields to do manually, you could iterate through each field in the model to do the filter: 如果手动执行的字段太多,您可以遍历模型中的每个字段来执行过滤:
for field in ModelA._meta.get_all_field_names():
try:
d = {field: "None"}
ModelA.objects.filter(**d).update(**{field: None})
except:
pass
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.