我尝试对扩展字段进行过滤,正如以下示例所示,它实际上根本不是一个字段。为了这个例子,假设我们有一个正在运行的 Django,安装了 django-filer 并且已经上传了一些文件。
>>> from filer.models import File
>>> File.objects.all()[0].extension
'some_ext' # just as example
但是在尝试过滤时:
>>> File.objects.filter(extension='pdf')
django.core.exceptions.FieldError: Cannot resolve keyword 'extension'
into field. Choices are: _file_size, clipboarditem, description,
downloadfilemodel, file, filer_image_file, folder, folder_id,
has_all_mandatory_data, id, in_clipboards, is_public, modified_at,
name, news_attachment, original_filename, owner, owner_id,
polymorphic_ctype, polymorphic_ctype_id, sha1, uploaded_at
这是因为扩展不与模型一起存储,但实际上是计算属性。
我的问题:不将此元数据存储在文件模型中的理由是什么。
更新:我不抱怨实施。我询问实施的可能动机。