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 u开发者_JS百科se this class in the admin site, if possible.
Is my wild dream possible?
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...
class Things(model.Models):
file = CharField(max_length = 25, primary key = True)
content = TextField()
_objects = CharField(max_length = 50)
@property
def objects(self):
return load_content_from("/one directory/myPrefix_" + self._objects)
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).
精彩评论