管理器提供来自文件而不是数据库的查询集
我想重写管理器类,以便允许将内容数据从文本文件(此处为“/one directory/myPrefix_*”)加载到内容字段中,而不是从数据库表中加载。
class Things(model.Models):
file = CharField(max_length = 25, primary key = True)
content = TextField()
objects = myManager("/one directory/", "myPrefix_")
如果可能的话,我很乐意在管理站点中使用此类。
我的疯狂梦想可能实现吗?
I would like to override the manager class in order to allow content data to be loaded from text files (here on of "/one directory/myPrefix_*") into content field instead of from a database table.
class Things(model.Models):
file = CharField(max_length = 25, primary key = True)
content = TextField()
objects = myManager("/one directory/", "myPrefix_")
I would appreciate to use this class in the admin site, if possible.
Is my wild dream possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将通过将对象重命名为 _objects,然后创建一个属性函数来加载数据来解决这个问题。类似下面的代码应该可以满足您的需要...
如果您想查看管理站点中文件的内容,那么您可能需要创建自己的字段类型(请参阅 http://code.djangoproject.com/browser/django/trunk/django/db/models/fields )。
I would solve this by renaming objects to _objects, and then creating a property function to load the data. Something like the code below should do what you need...
If you want to see the content from the files in the admin site then you'll probably need to create your own field type (see http://code.djangoproject.com/browser/django/trunk/django/db/models/fields).