开发者

Django queryset filter for blank FileField?

How do I perform a Django 开发者_如何学编程queryset filter looking for blank files in FileField fields?

The field isn't null, it has a FileObject in it that doesn't have a file.


I was having this issue too, and finally found the solution!

no_files = MyModel.objects.filter(foo='')

This works because internally, the FileField is represented as a local file path in a CharField, and Django stores non-files as an empty string '' in the database.


An alternative solution:

no_files = MyModel.objects.filter(foo__in=['',None])
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜