Search code examples
pythondatabasedjango-modelsmodelinglarge-data

When a property of a model is a huge text


If a model in an application has a very large(in size) text property and even longtext would not be able to contain it, one possible way to store it seems to store it in a text file and use the text location as field of the database. However I am not sure with such a strategy what would be proper for naming this property?

For example suppose we have:

class Novel(models.Model):
    ???? = models.CharField(max_length=200)

Should I name this property novel_text or novel_text_path? And is this a proper way of storing huge texts?

I hope this doesn't seem as a silly question.

Thanks.


Solution

  • If you want to store this text in a separate file I would recommend to name it novel_text_file or something similar to make it as clear and logical as possible and as Pratik wrote I would use Django's filefield.

    But I don't think this is the best solution for storing data like this. Imagine if you need to scale up your system. Storing data in files make it significantly harder. You have to sync files to all server or share them.

    One possible solution is using MongoDB's GridFS. This might be useful: http://django-mongodb.org/topics/gridfs.html