我使用 django-nonrel,Postgre 作为数据库,Mongo 作为文件存储。
我的模型看起来像这样并且工作正常
class Doc(models.Model):
created_on = models.DateTimeField(auto_now_add=True)
file = models.FileField(storage=gridfs_storage, upload_to='/')
并且工作正常
Doc.objects.all()[0].file.size
108776
现在我正在尝试聚合大小以获得查询集的总大小。
我试过了
Doc.objects.all().aggregate(Sum('file__size'))
但是这个扔
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Users/zoidberg/dev/backus/lib/python2.6/site-packages/django/db/models/query.py", line 321, in aggregate
is_summary=True)
File "/Users/zoidberg/dev/backus/lib/python2.6/site-packages/django/db/models/sql/query.py", line 974, in add_aggregate
field_list, opts, self.get_initial_alias(), False)
File "/Users/zoidberg/dev/backus/lib/python2.6/site-packages/django/db/models/sql/query.py", line 1417, in setup_joins
raise FieldError("Join on field %r not permitted. Did you misspell %r for the lookup type?" % (name, names[pos + 1]))
FieldError: Join on field 'file' not permitted. Did you misspell 'size' for the lookup type?
enter code here
知道是否可以使用 ORM 或者我必须自己迭代文件?